|
Boost : |
From: Ken Hagan (K.Hagan_at_[hidden])
Date: 2003-02-19 05:31:14
>> From: Steve Clamage <stephen.clamage_at_[hidden]>
>> To: C++ core language mailing list
>> Message c++std-core-9820
>>
>> Some compilers implement thread-local storage (TLS) for what would
>> otherwise be global variables. The compiler and runtime system
>> arrange for each thread to see its own copy of a global variable.
As I understand it, TLS on Windows is just a fancy wrapper around
a pointer. The "thread-local" slots are addressed relative to some
register that the OS sets up for each thread. So in...
extern int k;
int i = k;
...if k is thread-local, &k is an offset that must be dereferenced
with respect to the current thread. I see a fairly good analogy with
pointers to members.
extern int __thread_context::* pmk; // a TLS variable
int i = __thread->*pmk;
The only differences are that you don't need to write "__thread->*"
and that TLS variables are "pointers to references".
In implementation terms, pmk is a compile-time constant, so I think it
could be an acceptable template parameter. On the other hand, the code
required to extract the integer value is different from the code
required
to dereference a normal variable. On the third hand, compilers
supporting
TLS already face this problem when I write...
__declspec(thread) int k;
int* pk = &k;
...and I don't think being a template parameter adds anything new.
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk