Subj : Re: Can C++ local static objects be made thread safe? To : comp.programming.threads From : Gianni Mariani Date : Tue Feb 15 2005 09:38 pm Alexander Terekhov wrote: .... > > And don't forget that compilers also reorder. In the case I gave above, the compiler is not allowed to re-order if it's conforming. In the case of > overly constrained hardware, "per-thread" synchronization is > needed to preclude "bad things" on *compiler's* part (hardware > aside for a moment). In the example I gave, hardware is the issue. > > [...] > >>describe here. Each thread has different memory mapped to the same >>address (don't try to take the address of an __thread variable though). > > > Why so? From a disassemble of : static __thread Type * x; if ( ! x ) mov %gs:0x0,%eax test %eax,%eax jne xxxx You'll notice the %gs segement specifier. I suspect that the gs: points to a different segment for each thread. If you try to take the address, you're not pointing to the same place. I liked the SGI Irix way where the same address was mapped to different pysical memory for each thread. .