Boost logo

Boost Users :

Subject: Re: [Boost-users] at_thread_exit() never getting called
From: Peter Dimov (pdimov_at_[hidden])
Date: 2009-11-06 11:44:30


cowwoc wrote:
> Anthony Williams-4 wrote:
>>
>> OK, what is your desired behaviour in these circumstances?
>>
>> (1) main() thread uses at_thread_exit() and then main() returns
>>
>> (2) main() thread uses at_thread_exit() and calls exit()
>>
>> (3) main() thread uses at_thread_exit(). *Another* thread calls
>> exit()
>>
>> (4) *another* thread uses at_thread_exit(). main() returns
>>
>> (5) *another* thread uses at_thread_exit(). main() calls exit()
>>
>> (6) *another* thread uses at_thread_exit() and then calls exit()
>>
>> Note that returning from main() is the same as calling exit(), and
>> abruptly terminates all threads.
>
> Hi Anthony,
>
> For all cases mentioned above I would expect the shutdown hook to get
> invoked.

The at_thread_exit hooks are invoked in the context of the thread. When exit
is called, the threads are executing something, and it is not possible to
make them stop whatever they are doing in order to execute the
at_thread_exit hooks (and it would be a bad idea were it possible, because
the thread state could be inconsistent and cause a crash in the hook.)

It's possible to execute the at_thread_exit hooks just for the thread that
called exit(), but this is inconsistent and effectively duplicates atexit.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net