Date: Tue, 17 Jun 2003 17:41:11 +0400 (MSD) From: Igor Sysoev <is@rambler-co.ru> To: threads@freebsd.org Subject: Re: Nvidia, TLS and __thread keyword -- an observation Message-ID: <Pine.BSF.4.21.0306171714110.326-100000@is> In-Reply-To: <20030617071810.GA2451@dhcp01.pn.xcllnt.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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)
In FreeBSD we use gs to point to KSE specific data
gs -> [ KSE specific data ]
[ current thread ] -> [ thread specfic data ]
[ tls_array ]
and then same C code can be translate to
mov tls_key, %ecx
mov $gs:current_thread, %eax
mov tls_array(%eax), %eax
mov (%eax,%ecx,4), %eax
mov $1, (%eax)
And I think we should use this scheme not only in libkse but in libthr too
to be binary compatible.
Igor Sysoev
http://sysoev.ru/en/
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?Pine.BSF.4.21.0306171714110.326-100000>
