4 ms·
> When you declare a "static __thread char p", how do you know that for instance this is located at the 123th word of the per-thread area? Believe it or not, i
by geocar 2y ago
> When you declare a "static __thread char p", how do you know that for instance this is located at the 123th word of the per-thread area?
Believe it or not, it's exactly the same way it knows that "static char p" is located at the 123rd word of the data section: The linker does it!
> What if that declaration is on a dynamic library, which was loaded late (dlopen) into the process?
Same thing, except the linker is dynamic.
> What about threads which were started before that dynamic library was loaded, and therefore did not have enough space in their per-thread area for that thread-local variable, when they call into code which references it? What happens if the thread-local variable has an initializer?
Seriously? I mean, you probably do have enough space because address space is huge, but dlopen should move TLS.
> links to a 81-page document describing four TLS access models, and that's just for Unix-style ELF
Just because someone can write 81-pages about something doesn't mean that it takes 81-pages to understand something.