3 ms·
Take a look at https://maskray.me/blog/2021-02-14-all-about-thread-local-storage https://maskray.me/blog/2021-02-14-all-about-thread-local-st... I think what y
by atq2119 2y ago
Take a look at https://maskray.me/blog/2021-02-14-all-about-thread-local-storage https://maskray.me/blog/2021-02-14-all-about-thread-local-st...
I think what you want is to force the "initial exec" model using an attribute to get the more efficient code.
IIRC this (or something equivalent) is what libGL does because basically every OpenGL function call needs to read the thread-local variable holding the current GL context.
The downside is that dlopen()ing your library may fail.
- yosefk 2y agoDoesn't the "initial exec" model require the user to run the executable with LD_PRELOAD=your.so or linking against your.so (DT_NEEDED)? eg would it work with a Python extension module which is dlopen'd at runtime?
- fweimer 2y agoIt depends on the amount of TLS and the number of objects that do this, and the C library. In glibc, we have a small static TLS reservation dedicated for use by dlopen of shared objects with initial-exec.