I am new to multithreading in C and I had this question. I wrote the following code:
#include #include #include
You're passing the address of a variable the for is changing (i) so you're at the mercy of the scheduler. You should just pass a copy. As a cheap, not completely-kosher way:
for
i
pthread_create(&thread[i],&attr,test, (void*)i); /* ... */ int i = (int)a;