[LLVMdev] Advice on implementing fast per-thread data

Chris Lattner sabre at nondot.org
Tue Feb 5 16:09:16 PST 2008


On Tue, 5 Feb 2008, Brian Hurt wrote:
>> You should read up about it then. :)
>> Start here: http://people.redhat.com/drepper/tls.pdf
>>
>
> Thank you.  You've just made my life about 3000% easier.  Somehow I've

:) Happy to help,

> Playing around a little bit with this, I find that:
> static __thread int i;
>
> int foo(void) {
> 	i += 1;
> 	return i;
> }

> So, other than the segment override, this is no different than accessing a
> global variable.  Which means I don't have to give up a clock cycle on
> allocation speed for the common case (actually doing a collection is a
> little bit trickier).

Doing a collection should be relatively straight-forward.  You can take 
the address of these TLS variables, and I believe that the address is 
visible across threads.  Just take the address in the startup for each 
thread that is created, and store it in some global list that the 
collector walks.

-Chris

-- 
http://nondot.org/sabre/
http://llvm.org/



More information about the llvm-dev mailing list