thread-local storage

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Post Reply
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

thread-local storage

Post 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 ...
Tim

Re:thread-local storage

Post 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.
Post Reply