Код:Почему pthread_exit действует как pthread_join?
void *PrintHello(void *threadid)
{
cout<<"Hello"<<endl;
sleep(3);
cout<<"Still PrintHello is alive"<<endl;
}
int main (int argc, char *argv[])
{
pthread_t threads[NUM_THREADS];
cout<<"Calling thread:"<<t<<endl;
pthread_create(&threads[0], NULL, PrintHello, NULL);
//pthread_join(threads[0],NULL);
cout<<"Main exits"<<endl;
pthread_exit(NULL);
}
Почему pthread_exit(NULL)
здесь действует как pthread_join()
? i.e Зачем выходить main
, не разрушая нить printHello
и позволяя продолжить?