Re: atexit handler: pthread_cancel, pthread_testcancel, pthread_join problem



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.

.



Relevant Pages

  • Re: complete all the fields before exit
    ... It cancels the update if in any of the TextBox controls are Null (nothing ... Exit_Proc: Exit Sub ... "Larry Linson" wrote: ...
    (microsoft.public.access.forms)
  • Re: Cancellers that perforate.
    ... defacing is called an 'obliterator' for good reason. ... pen cancels, again worthless as far as being collectable. ... a daub of ink on a stamp. ...
    (rec.collecting.stamps.discuss)
  • Re: The Abbey Road streetsign
    ... auction, or had their bids cancelled for one reason or ... administrative cancels ... What I wanted to know was the underlying reason why the bidding ... testing the water. ...
    (uk.people.consumers.ebay)
  • Re: WARNING: Your messages are being cancelled
    ... > If you participate in any of the dozens of newsgroups that JF Mezei infects, ... > He forges the names and e-mail addressess of newsgroup participants and cancels ... hands and nothing better to do but post messages like that to the ... The only reason they don't put a proper name to the posts is because ...
    (comp.os.vms)
  • Re: Taking the pledge
    ... about thrid party cancels... ... I see no reason it shouldn't work. ... PLEASE identify your response so that others can filter his ...
    (rec.aviation.piloting)

Loading