Usenet comp.unix.osf.osf1 (1992-2004)
 help / color / mirror / Atom feed
* Thread Local Storage
@ 1997-06-13  4:00 Mike Parker
  1997-06-16  4:00 ` Dave Butenhof
  0 siblings, 1 reply; 2+ messages in thread
From: Mike Parker @ 1997-06-13  4:00 UTC (permalink / raw)



Hey there!

We're doing some multi-threaded programming on DEC Unix 4.0b using the 
DEC C++ compiler (v5.5-004) and have a question about static thread 
storage.

How do we define a variable that is static within the thread, i.e., it is 
created when the thread is created and is destroyed when the thread goes 
away.

I think the solution should be provided by the compiler. Something like 
the extended storage attribute 'thread' in Microsoft c++.

Thanks to any and all,

mp

Mike.Parker@us.gases.BOC.com



^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Thread Local Storage
  1997-06-13  4:00 Thread Local Storage Mike Parker
@ 1997-06-16  4:00 ` Dave Butenhof
  0 siblings, 0 replies; 2+ messages in thread
From: Dave Butenhof @ 1997-06-16  4:00 UTC (permalink / raw)



Mike Parker wrote:
> 
> Hey there!
> 
> We're doing some multi-threaded programming on DEC Unix 4.0b using the
> DEC C++ compiler (v5.5-004) and have a question about static thread
> storage.
> 
> How do we define a variable that is static within the thread, i.e., it is
> created when the thread is created and is destroyed when the thread goes
> away.
> 
> I think the solution should be provided by the compiler. Something like
> the extended storage attribute 'thread' in Microsoft c++.

First, beware that "thread static storage" (usually known as TLS, for
"thread local storage") is an illusion. It's not static, and it's far
from free. POSIX threads provides "thread specific data" (TSD), and TLS
is mostly an expensive layer of compiler "syntactic sugar" on top of
TSD. Yes, it has to be supported by the compiler, and current versions
of the compilers don't.

Furthermore, extensions to the POSIX TSD model are required to do TLS
correctly, and 4.0b doesn't support those extensions -- there's nothing
a compiler can do about this. (I've written the necessary extensions,
and they're in a release stream, but it wouldn't be appropriate for me
to make any announcements about when those extensions might ship, much
less about compiler or development tool support.)

In terms of efficiency, TLS can be nice if you have a situation where
all (or nearly all) of the threads in a process will frequently access
per-thread data. Because TLS is created automatically at thread startup,
it allows you to use the data without checking whether you need to
create it. If most of your threads frequently use the same per-thread
data, that can be a substantial savings.

If most of your threads don't use a TLS value, then TLS can be expensive
because the threads still have to allocate and initialize per-thread
copies of the data at startup, and then destroy that (unused) copy at
termination. In that case you're far better off using the POSIX TSD
interfaces directly, creating per-thread copies dynamically only in the
threads that need it.

/---------------------------[ Dave Butenhof ]--------------------------\
| Digital Equipment Corporation           110 Spit Brook Rd ZKO2-3/Q18 |
| 603.881.2218, FAX 603.881.0120                  Nashua NH 03062-2698 |
| butenhof@zko.dec.com               http://members.aol.com/drbutenhof |
\-----------------[ Better Living Through Concurrency ]----------------/



^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1997-06-16  4:00 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1997-06-13  4:00 Thread Local Storage Mike Parker
1997-06-16  4:00 ` Dave Butenhof

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox