LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Programming (https://www.linuxquestions.org/questions/programming-9/)
-   -   pthread_join (https://www.linuxquestions.org/questions/programming-9/pthread_join-126624/)

dummyagain 12-17-2003 08:55 AM

pthread_join
 
What's the function and use of pthread_join, can u give an example for this?

shishir 12-18-2003 03:04 AM

well the purpose of pthread_join is to "join the created thread" into the caller thread...
this makes sure that your thread does get to run before the process falls off the closing brace in main.....

may be looked at vaguely as a sort of a wait for threads...

eg:
//code
#include <stdio.h>
#include <pthread.h>
void *func(void *arg)
{
printf ("inside the thread %d\n",pthread_self());
return NULL;
}

int main (void)
{
pthread_t tid;

pthread_create (&tid,NULLm func,NULL);

pthread_join (tid,NULL);

return 0;
}
------the above code guarantees that your thread gets a chance to run...
if you try the above code with out the pthread_join ...the thread may or may not get to run...

so....this is to make sure that your thread does run...
for more details see http://campuscgi.princeton.edu/man?pthread_join

also go thru a book called advanced linux programming....freely available on the net (http://www.advancedlinuxprogramming.com/)....it explains many of the nuances of the threads....


All times are GMT -5. The time now is 02:09 AM.