[PATCH 12/23] nptl: Introduce __nptl_deferred_init
Carlos O'Donell
carlos@redhat.com
Fri May 14 19:16:08 GMT 2021
On 5/14/21 9:29 AM, Adhemerval Zanella via Libc-alpha wrote:
>
>
> On 14/05/2021 09:22, Florian Weimer wrote:
>> * Adhemerval Zanella:
>>
>>> On 13/05/2021 17:51, Florian Weimer wrote:
>>>> * Adhemerval Zanella:
>>>>
>>>>> On 12/05/2021 13:58, Florian Weimer via Libc-alpha wrote:
>>>>>> This function is called once by pthread_create, before spawning
>>>>>> the first thread, and also within pthread_cancel. Since it sets up
>>>>>> cancellation handlers, place it along with the pthread_cancel
>>>>>> implementation within libc.
>>>>>
>>>>> Why does it need to be initialized by pthread_create as well? I think
>>>>> moving the initialization to pthread_cancel and only setting once
>>>>> when pthread_cancel is called (and not tying to __libc_single_threaded)
>>>>> is slight better since it avoids the setup of SIGCANCEL for programs
>>>>> that do not use cancellation.
>>>>
>>>> We need to unblock SIGCANCEL anyway, so that we can send the signal.
>>>> This part can't be deferred until pthread_cancel is called.
>>>
>>> Yes, what it seems to be wrong is unblocking it on both pthread_create
>>> *and* on pthread_cancel.
>>
>> We need to unblock in pthread_cancel too, to support self-cancel in a
>> single-threaded process.
>
> We don't really need in fact, pthread_cancel can call __pthread_exit
> directly if the argument is THREAD_SELF. And with my canceltype and
> cancelstate refactor we don't even need the whole atomic bit set
> support.
And POSIX in the RATIONALE says exactly this:
~~~
The special function also means that implementations are not obliged
to implement cancellation with signals.
~~~
https://pubs.opengroup.org/onlinepubs/9699919799/functions/pthread_cancel.html
>> Do you know if we ever change the signal mask to enable/disable
>> asynchronous cancellation? I don't think so. Then we could support
>> self-cancel simply by calling the signal handler. (It would not matter
>> whether the process is multi-threaded or not.)
>>
>> If we do that, I think it is simpler to do all the initialization in
>> pthread_create.
>>
>> Thanks,
>> Florian
>>
>
--
Cheers,
Carlos.
More information about the Libc-alpha
mailing list