This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

RE: thread-local storage (was: BAD NEWS - Apache ...)


Fergus Henderson[SMTP:fjh@cs.mu.oz.au] wrote:
>Is
>
>	#define THREADLOCAL __attribute__((section(".tls")))
>	int foo THREADLOCAL = 42;
>
>enough, or does the compiler need to generate special code for accessing
>thread-local storage?

>From the section of "Advanced Windows" (Jeffery Richter, Microsoft Press)
on static thread local storage:

---Quote---
To actually make static TLS work, the operating system needs to get involved. When your application is loaded into memory, the system looks for the .tls section in your EXE file and dynamically allocates a block of memory large enough to hold all the static TLS variables. Every time the code in your application refers to one of these variables, the reference resolves to a memory location contained in the allocated block of memory. As a result, the compiler must generate additional code in order to reference the static TLS variables, which makes your application both larger in size and slower to execute. On an x86 CPU, three additional machine instructions are generated for every reference to a static TLS variable.
---Endquote---

Which sounds to me like the compiler has to do some special stuff (and
that makes sense to me). I really don't know exactly what that stuff
might be... presumably accessing some special thingamajig that makes
sure the reference is made to the appropriate block given the current
thread (perhaps part of an internal thread context structure?).

Anyway, like I said, I don't think that is up and running in the GCC
compiler yet (though I would love to be shown wrong).

Colin.

-- Colin Peters - colin@bird.fu.is.saga-u.ac.jp
-- Saga University Dept. of Information Science
-- http://www.fu.is.saga-u.ac.jp/~colin/index.html
-- http://www.geocities.com/Tokyo/Towers/6162/

-
For help on using this list (especially unsubscribing), send a message to
"gnu-win32-request@cygnus.com" with one line of text: "help".


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]