[PATCH 1/2] Add the __libc_single_threaded variable

Szabolcs Nagy szabolcs.nagy@arm.com
Thu May 21 13:26:41 GMT 2020


The 05/21/2020 15:16, Florian Weimer wrote:
> * Szabolcs Nagy:
> > The 05/20/2020 20:12, Florian Weimer via Libc-alpha wrote:
> >> The variable is placed in libc.so, and it can be true only in
> >> an outer libc, not libcs loaded via dlmopen or static dlopen.
> >> Since thread creation from inner namespaces does not work,
> >> pthread_create can update __libc_single_threaded directly.
> >> 
> >> Using __libc_early_init and its initial flag, implementation of this
> >> variable is very straightforward.  A future version may reset the flag
> >> during fork (but not in an inner namespace), or after joining all
> >> threads except one.
> >> ---
> > ...
> >> +* The GNU C Library now provides the header file <sys/single_threaded.h>
> >> +  which declares the variable __libc_single_threaded.  Applications are
> >> +  encouraged to use this variable for single-thread optimizations,
> >> +  instead of weak references to symbols historically defined in
> >> +  libpthread.
> >
> > i wonder if the new header can be included into
> > threads.h and pthread.h, and a feature macro added
> > for it, so users can avoid doing a header check.
> 
> Isn't __has_include in current compilers sufficient for that?
> 
> The advantage of the current approach is that libstdc++ headers can use
> __has_include on the new headers, without pulling in other headers which
> declare identifiers which are not in implementation namespace and also
> not expected to be used by C++ standard headers.

ok i guess __has_include is fine (assuming the macro expansion
bugs are fixed)


More information about the Libc-alpha mailing list