Hello.
I want to print out the content of integer array of each processes. Problem is, it's all cluttered because of race condition.
What is the simplest solution? I don't want to debug. I want to show the contents because I'm doing sorting algorithm. So it's useful to show before and after sort.
I added this in lock.c:
#include <stdio.h>
static int lock=0; //Don't use if timing execution
void capture(int rank) {
while(lock!=0);
lock = 1;
printf("\nCaptured by %d\n", rank);
}
void release() {
lock = 0;
}
And call capture() before printing stuff, then release() after printing. Yes, it's a semaphore-like hack. But it isn't working, any ideas?