Re: pthread_join
- From: loic-dev@xxxxxxx
- Date: 15 Feb 2006 12:50:34 -0800
Hello,
can some one tell me when you would need to use pthread_join.
pthread_join() is needed when:
1) You want to make sure that a thread has terminated before proceeding
further, or
2) You want the return value of a terminated thread.
Of course you might want to have both 1) and 2).
By default, threads are created joinable. When a thread terminates,
its thread id, the return value and possibly other resources (like
thread stack) are retained by the Pthreads implementation. Until the
defunct thread has been joined from another thread using
pthread_join().
If you don't need to wait for the thread's completion, and you don't
need the thread's return value, then you might want to detach the
thread. This can be done by using the function pthread_detach(). When
you detach a thread, you tell the Pthreads lib that it can release all
the resources associated to the thread when it terminates.
By the way, if you're creating an important number of joinable threads,
but never join them, then you can run into the situation where you
can't create a new thread because resources are lacking.
i want some practice programs on posix threads.suggest me the site names to
get good understanding of pthreads.
I don't know any good tutorial about Pthreads on the net, but if you're
looking for a good book, then I warmly recommend:
"Programming with Posix Threads" from David Butenhof (ISBN
0-201-63392-2).
HTH,
Loic.
.
- Follow-Ups:
- Re: pthread_join
- From: dick.dunbar
- Re: pthread_join
- References:
- pthread_join
- From: lak
- pthread_join
- Prev by Date: Re: Confused about pthread_cond_timedwait
- Next by Date: Re: Confused about pthread_cond_timedwait
- Previous by thread: Re: pthread_join
- Next by thread: Re: pthread_join
- Index(es):
Relevant Pages
|