Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- From: loic-dev@xxxxxxx
- Date: 19 Aug 2005 00:56:07 -0700
Halla Anna,
> > I share Joe's opinion here. It doesn't make a lot of sense to register
> > an atexit handler that cancels the thread. The function exit() does
> > just that.
>
> Does this suggest that exit() will do a pthread_cancel() for
> other threads running? For example, if I have a thread whose
> start routine is
Usually, no. When you call exit() all the threads within the process
cease to exist. A thread doesn't necessarily terminate at a
cancellation point.
I guess, the question you should ask yourself is: Is there a reason why
I want to cancel my thread upon process exit? Can my thread just be
terminated anywhere?
> void* start_thread(void* something)
> {
> for(;;)
> {
> // lengthy operation A
> pthread_testcancel(); // op. B
> // lengthy op. C
> }
> }
>
> If I don't call pthread_cancel() explicitly for the above thread,
> will the above thread still get cancelled only at operation B?
"Cancelled" is the wrong word. It might be terminated during operation
A, during the pthread_testcancel() or during operation C.
If - for some reasons - you really need that your process exits only at
cancellation points, proceed (for instance) as follows:
1) dedicate a thread that waits on the condition variable "process is
exiting".
2) after wake up, this thread cancels the other threads.
3) Finally it eventually joins, and call exit().
4) At the places where the process must terminate, signal the condition
variable "process is existing"
HTH,
Loic.
.
- References:
- atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- From: annamalai . gurusami
- Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- From: Joe Seigh
- Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- From: loic-dev
- Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- From: annamalai . gurusami
- atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- Prev by Date: Re: NPTL and sigwait() problem under linux
- Next by Date: Re: pthreads (linux) questions
- Previous by thread: Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- Next by thread: Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem
- Index(es):
Relevant Pages
|
Loading