> a key word to support this. For example, the following code declares an
> integer thread
> local variable and initializes it with a value:
>      __declspec( thread ) int tls_i = 1;
> I'm puzzled about how this is implemented. I hope someone can talk about
> it, and most
> importantly, is something similar implemented in Linux?

Typically it is done by having a thread local segment register. Windows
uses fs: for this from memory. This of course isnt stunningly portable

pthreads has its own generic scheme - see man pthread_key_create.

Another approach some people use (and which is used in the kernel) is to
define a struct of the thread private storage and put it on the bottom of
the thread stack. Allocate the stacks with a given boundary and you can now do

                movl %esp, %eax
                andl $FFFFF000, %eax            // or whatever size 
                        
to get a pointer to thread local storage. Not only is that as fast as using
a segment override (often faster) but you can do it once for several values.

This is how the kernel does it. The task structures for the kernel live
in the kernel stack this way.

Alan

-- 
To unsubscribe:
mail -s unsubscribe [EMAIL PROTECTED] < /dev/null

Reply via email to