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循环。这是什么原因?