Nvidia, TLS and __thread keyword -- an observation

Marcel Moolenaar marcel at xcllnt.net
Tue Jun 17 09:40:59 PDT 2003


On Tue, Jun 17, 2003 at 05:41:11PM +0400, Igor Sysoev wrote:
> On Tue, 17 Jun 2003, Marcel Moolenaar wrote:
> 
> > There's a definite advantage to supporting the __thread keyword in
> > userland and we should add the support. It really isn't that hard,
> > but it requires some thought and testing. In most cases you simply
> > point your thread pointer between the control structure and the
> > thread local segments.
> 
> If the thread implementation uses gs register to point to thread
> specific data:
> 
>    gs -> [ thread specific data ]
>          [ tls_array ]
> 
>    then this C code
> 
>    __thread  int a;  a = 1;
> 
>    can be translated to
> 
>    mov  tls_key, %ecx
>    mov  $gs:tls_array, %eax
>    mov  (%eax,%ecx,4), %eax
>    mov  $1, (%eax)

The runtime specification of the platform generally dictates
how TLS access sequences are to be generated. This influences
how you want to implement your thread library. It's not the
other way around. If our use of %gs on i386 conflicts with the
runtime specification (extension), we need to change.

I would also appreciate a less i386-oriented mindset on this
list. What may not be a "true" standard on i386, is on ia64.

-- 
 Marcel Moolenaar	  USPA: A-39004		 marcel at xcllnt.net


More information about the freebsd-threads mailing list