On Fri, 2007-11-02 at 10:29 -0700, Ian Lance Taylor wrote: > skaller <[EMAIL PROTECTED]> writes: > > > On Fri, 2007-11-02 at 07:39 -0700, Ian Lance Taylor wrote: > > > skaller <[EMAIL PROTECTED]> writes: > > > > > In a C executable, TLS requires one extra machine register. > > > > You mean gcc? > > I don't understand the question. I mean in a C/C++ executable which > uses TLS. By TLS I mean __thread, not pthread_get_specific. In the > GNU/Linux world, TLS conventionally means specifically __thread.
I see why you didn't understand the question .. you're so buried in gcc world C=gcc .. whereas for me C=ISO Standard, any compiler. TLS = __thread jargon noted, thanks (for me, TLS meant both generic 'storage local to a thread=the stack' or 'posix', not __thread which is a gcc extension). > It only costs a register for code which accesses a TLS variable, of > course. What do you mean 'code'? Do mean individual function? If so, how is the register loaded? > While global variables are rarely required, there are many cases where > a class is most reasonably implemented using static variables. For > example, it's very hard to implement malloc without using any static > variables. That's true, and again is an example of a badly designed function in the C standard, probably a legacy of the days when the OS supplied each individual heap block (and long before threads existed). This should really be done with two functions: one that fetches large block from the OS, and another than suballocates it. That avoids any static variables and would permit unsynchronised allocation in threaded code if the programmer designed it that way. > And for performance those static variables should be > thread local. > > It's just not plausible to say that a C/C++ program should be written > without static variables. Rubbish:) 30 years of programming, never used one in serious code unless some brain dead API forced it. > Modern programs are written by different > organizations. There is no way to pass appropriate state through all > the required interfaces. Of course there is. It's called design by contract. I do it all the time. I am appalled at code bases like GTK and interfaces like OpenMP which get such really basic things wrong. -- John Skaller <skaller at users dot sf dot net> Felix, successor to C++: http://felix.sf.net