samedi 28 mars 2015

Why pthread_exit acts like pthread_join?


Code:



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);
}


Why pthread_exit(NULL) here acts like pthread_join()? i.e Why exiting main not destroying the printHello thread and allowing it to continue?




Aucun commentaire:

Enregistrer un commentaire