#include
#include
#include
void test(void *arg);
pthread_mutex_t mutex;
int main()
{
pthread_t t_id;
for(int i=0;i<50;i++)
{
pthread_create(&t_id,NULL,test,(void)&i);
}
pthread_mutex_destroy(&mutex);
}
void test(void *arg)
{
pthread_detach(pthread_self());
int i=(int*)arg;
printf("%d:\n",i);
return NULL;
}
请前辈看看这段代码,为什么输出会有重复的数字,有时候输出数量还会少于50,当把pthread_detach()换为pthread_join()的时候就很正常了,求解答。