On 02.02.2017 12:04, Nick Kew wrote:
> On Wed, 2017-02-01 at 00:23 +0100, Stefan wrote:
>> Hi,
>>
>> the issue was discovered as part of tracing down a deadlock condition in
>> an SVN test [1].
>>
>> As far as I understand it, the problem lies in the C-standard not
>> explicitly defining when a function registered with atexit() is called
>> in the context of thread termination [2].
> I had no idea atexit() was called on thread termination.

It's not.

>   I guess the
> manpage must be misleading in telling us it happens at process exit? 
>
>>     atexit(apr_terminate);
>>     apr_initialize();
> That whole widely-used idiom looks deeply suspect if multiple
> thread exits will each invoke the atexit!  Are you sure this
> isn't just a platform bug?  In which case, a patch should perhaps
> live in platform-specific code?

That answer in SO is nether here nor there. In C (and C++), atexit()
handlers are called when the main() function terminates; either duet to
a call to exit(), or due to an implicit or explicit return from main().
And the "Linux" function _exit() is something else than the standard C
exit() and is closer in semantics to standard C _Exit().

I don't have a recent edition of the C standard available; I do know
that C90 has nothing to say about threads. The C++11  standard does
describe what happens on thread termination and says nothing about
atexit handlers being called. I'd be surprised if C++ behaviour was
different from C in this case.

-- Brane

Reply via email to