Subject: Re: proposal: join me for thread-safeness
From: [email-masked] (Fergus Henderson)

28 Oct 1997 09:49:30 -0800
Message-ID: <[email-masked]>
References: <[email-masked]>
To: [email-masked]
Cc: [email-masked]

Peter Boncz <[email-masked]> writes:

>To my surprice, the newlib/ (other than has been mentioned on this list) has
>been programmed with thread-safeness in mind. It uses the _REENT structure
>wherever appropriate. Please correct me if I'm wrong. It's just that there is
>just one instance of _REENT in cygwin.dll (called impure_ptr, or something 
>like it) that makes newlib unsafe at this moment.
>
>Producing a different _REENT for each thread will *not* be difficult to 
>implement since the WIN32 interface provides explicit functions to manipulate
>thread-local storage (Tls*()). Thus, it is not necessary in my view to
>modify gcc or the linker for dealing with .tls sections (as Gunther mentioned);
>you just redefine _REENT to the WIN32 call getting the thread-local data. 
>Maybe it is not hyper-efficient, but it will do.

Hmm... one call to TlsGetValue() for every occurrence of `stdout' or
`stdin', and, unless you hack the newlib code a fair bit, several such calls
for every occurence of `putchar()' or `getchar()'...  This will be
quite expensive for some programs.

Another alternative might be to reserve a register (perhaps one of the
segment registers ES, FS, or GS?) to hold a pointer to thread-local
storage.  However, I'm not sure if this is feasible.  You would need
some way of ensuring that this register is reloaded on context switches.
And if you use say EBX instead of ES/FS/GS, then the cost would be
losing a register... maybe this alternative is not so good.

--
Fergus Henderson <[email-masked]>   |  "I have always known that the pursuit
WWW: <http://www.cs.mu.oz.au/~fjh>   |  of excellence is a lethal habit"
PGP: finger [email-masked]         |     -- the last words of T. S. Garp.
-
For help on using this list (especially unsubscribing), send a message to
"[email-masked]" with one line of text: "help".