LinuxQuestions.org
Visit Jeremy's Blog.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 12-17-2003, 08:55 AM   #1
dummyagain
Member
 
Registered: Sep 2003
Posts: 74

Rep: Reputation: 15
pthread_join


What's the function and use of pthread_join, can u give an example for this?
 
Old 12-18-2003, 03:04 AM   #2
shishir
Member
 
Registered: Jul 2003
Location: bangalore . india
Distribution: openSUSE 10.3
Posts: 251

Rep: Reputation: 33
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....

Last edited by shishir; 12-18-2003 at 03:06 AM.
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
pthread_join with timeout. JCipriani Programming 1 03-02-2006 08:50 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 01:35 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration