[PATCH] BZ# 18125: setcontext: Call exit, not _exit, after last linked context executes.
Carlos O'Donell
carlos@redhat.com
Mon Mar 16 15:24:00 GMT 2015
On 03/14/2015 10:30 AM, Rich Felker wrote:
> On Fri, Mar 13, 2015 at 05:15:32PM -0400, Carlos O'Donell wrote:
>> There appears to be a discrepancy among the implementations
>> of setcontext with regards to the function called once the last
>> linked-to context has finished executing via setcontext.
>>
>> The POSIX standard says:
>> ~~~
>> If the uc_link member of the ucontext_t structure pointed to by
>> the ucp argument is equal to 0, then this context is the main
>> context, and the thread will exit when this context returns.
>> ~~~
>>
>> It says "exit" not "exit immediately" nor "exit without running
>> functions registered with atexit or on_exit."
>
> It says "the thread will exit", so you need to call pthread_exit, not
> _exit or exit. The latter cause the process to exit. Note that
> pthread_exit in the last thread results in exit being called.
That kind of change is outside the scope of this bug fix.
While in retrospect I agree with you, the interface in question is
deprecated and should not be used with pthreads, instead pthreads
should be used directly.
Thus we won't be 100% POSIX compliant until this gets fixed, but
we'll at least run registered exit functions.
Cheers,
Carlos.
More information about the Libc-alpha
mailing list