0
我有一個基本的程序來測試在pthread_create:爲什麼pthread_create以隨機順序創建線程?
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
long t;
for(t=0; t<NUM_THREADS; t++){
/* TODO assignment 3.2 a) */
pthread_create(&threads[t], NULL, SomeFunction, t);
// pthread_join(threads[t], NULL);
}
printf("Completed. Exiting\n");
pthread_exit(NULL);
}
每次我跑了它,它會在一個隨機的順序線程不考慮for循環。這是什麼原因?