[PATCH 2/2] manual: Document __libc_single_threaded
Florian Weimer
fweimer@redhat.com
Wed Jun 3 15:48:35 GMT 2020
* Adhemerval Zanella:
>> I'm going to add this to the manual as an implementation note, after the
>> first example:
>>
>> @c Note: No memory order on __libc_single_threaded. The
>> @c implementation must ensure that exit of the critical
>> @c (second-to-last) thread happens-before setting
>> @c __libc_single_threaded to true. Otherwise, acquire MO might be
>> @c needed for reading the variable in some scenarios, and that would
>> @c completely defeat its purpose.
>
> The comments is sound, but I still think we should properly document
> that this initial version does not attempt to update
> __libc_single_threaded on pthread_join or detach exit and maybe also
> the brief explanation you added on why this semantic was chose (to
> avoid the requirement of more strict MO).
I'm concerned that if we make the implementation too transparent,
programmers will read the explanation and say, “gosh, I better assign
true to __libc_single_threaded after I joined the last thread”. That's
not something we want to encourage.
>> For detached thread exits, this kind of synchronization may not be
>> easily obtainable in all cases. I don't think we can do it on the
>> on-thread exit path because the kernel will perform certain actions
>> afterwards (like robust mutex updates), no matter how late we do it. I
>> guess we could perhaps piggy-back on the stack reclamation mechanism.
>
> It seems that robust mutexes updates are indeed a problem, but I am not
> sure if CLONE_CHILD_CLEARTID clear helps here. It signals the thread
> is done with the memory synchronization, but the stack cache is not
> really updated. Maybe an extra clone3 flag ?
I thought we might piggy-back on the work that free_stacks does. But
the code is sufficiently convoluted that I'm no longer sure.
Thanks,
Florian
More information about the Libc-alpha
mailing list