When I run the following code it seems like the printout is not right.
void thread_Calc(int *pos) {
printf("recieved %d\n", *pos);
sig = -1;
mandel_Calc(&slices[*pos],maxIterations,&res[(*pos)*slices[*pos].imSteps*slices[*pos].reSteps]);
counter++;
array[counter] = *pos;
sig = *pos;
}
int main(int argc, char *argv[]) {
while (WinH % nofslices != 0) { nofslices++;}
slice_height = WinH/nofslices;
level = 1;
while (1) {
for (i=0; i<nofslices; i++){
array[i] = -1;
}
y=0;
sig = -1;
counter = -1;
for(i=0; i<nofslices; i++){
printf("Passing %d\n", i);
check=pthread_create(&worker[i], NULL, (void*)thread_Calc, (void*)(int *)&i);
if (check!=0) {
printf("Error in pthread_create\n");
return 0;
}
while (sig==-1||array[counter]==-1){
}
}
}
}
(This is just a part of my code, so assume that every variable is right and has a value).
The result I get is something like:
Passing 1
Passing 2
recieved 2
recieved 2
Passing 3
Passing 4
recieved 4
recieved 4
Passing 5
Passing 6
Passing 7
Passing 8
Passing 9
which seems like I can't always pass the right argument in pthread_create or something.