|
Boost Users : |
Subject: Re: [Boost-users] at_thread_exit() never getting called
From: cowwoc (cowwoc_at_[hidden])
Date: 2009-11-09 13:23:08
Anthony Williams-4 wrote:
>
> cowwoc <cowwoc_at_[hidden]> writes:
>
>> Peter Dimov-5 wrote:
>>>
>>> exit() will not hang, it will just terminate the thread (and all other
>>> threads) as its very last step (after invoking the atexit handlers and
>>> global/static destructors).
>>>
>>
>> But what happens if one of the handlers is itself waiting for the thread
>> to
>> shut down?
>
> If an atexit handler waits for a thread to shut down then it will
> block. If it is waiting for its own thread to shutdown then you have
> deadlock. That's easy to fix --- just set a flag to indicate to the
> atexit handler not to wait for this thread before you call exit.
>
>> Also, is at_thread_exit() implemented as an atexit() handler under the
>> hood?
>
> at_thread_exit is completely unrelated to atexit. It runs a function
> when the thread that called at_thread_exit returns from its thread
> function. For threads started with boost::thread this is done as part of
> the boost::thread internal thread management code. For threads started
> with platform-specific facilities such as CreateThread or pthread_create
> it is done using platform-specific hooks. Again, these do not interact
> with atexit handlers.
>
>> If not, how do you prevent it from killing the hook functions
>> prematurely?
>
> Calling exit() terminates all threads abruptly once the atexit handlers
> have run. Thread exit functions are not run for any threads. If threads
> are running at_thread_exit hooks they are terminated just as abruptly.
>
> Anthony
> --
> Author of C++ Concurrency in Action | http://www.manning.com/williams
> just::thread C++0x thread library | http://www.stdthread.co.uk
> Just Software Solutions Ltd |
> http://www.justsoftwaresolutions.co.uk
> 15 Carrallack Mews, St Just, Cornwall, TR19 7UL, UK. Company No. 5478976
>
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>
Anthony,
That really clears things up. I would suggest that the documentation for
at_thread_exit() mention these points.
Thank you,
Gili
-- View this message in context: http://old.nabble.com/at_thread_exit%28%29-never-getting-called-tp26053513p26271230.html Sent from the Boost - Users mailing list archive at Nabble.com.
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