Page 1 of 1

thread-local storage

Posted: Thu Jul 31, 2003 7:26 am
by Pype.Clicker
according to the latest "info gcc", it looks like gcc 3 now has a "per thread" class storage, called "__thread" that can be used to allocate thread-specific variables, which come very handy when doing multithreaded library programming (and do not wish to meddle with reentrant functions problems)

An object whose identifier is declared with the storage-class
specifier `__thread' has "thread storage duration". Its
lifetime is the entire execution of the thread, and its
stored value is initialized only once, prior to thread
startup.

The `__thread' specifier shall be used only with variables.
more informations about this new (?) feature may be found in GCC "info" pages, and informations about how it is implemented with ELF output files can be found at http://people.redhat.com/drepper/tls.pdf

i've not yet read through it, but i've no information about TLS for COFF binaries so far ...

Re:thread-local storage

Posted: Thu Jul 31, 2003 10:12 am
by Tim
Ooooh. MSVC has had this feature for a while ([tt]__declspec(thread)[/tt]), but it relies on features of PE. I'd be interested to read up on how gcc implements this.