This is the mail archive of the
pthreads-win32@sources.redhat.com
mailing list for the pthreas-win32 project.
Re: Thread local storage problem, and fix
- To: "Phil Frisbie, Jr." <phil at hawksoft dot com>
- Subject: Re: Thread local storage problem, and fix
- From: Ross Johnson <rpj at ise dot canberra dot edu dot au>
- Date: Thu, 23 Aug 2001 15:46:39 +1000
- CC: "pthreads-win32 at sourceware dot cygnus dot com" <pthreads-win32 at sourceware dot cygnus dot com>
- Organization: University of Canberra, Information Sciences and Engineering
- References: <3B83FF1D.DDB30CB0@hawksoft.com>
Hi,
I've added your change to the current CVS repository version.
Thanks.
Ross
"Phil Frisbie, Jr." wrote:
>
> While converting the simple per thread error storage in HawkNL over to POSIX and
> native Windows thread local storage, I came across some problems. I store a
> HawkNL error code for the thread, and if it is a Winsock error I set the error
> to NL_SOCKET_ERROR so the application can retrieve the real error code. But
> Winsock errors seemed to be cleared whenever pthread_getspecific() was called.
> They were also cleared by calling the native Windows TlsGetValue().
>
> So, I looked at the Pthreads-win32 source code for pthread_getspecific(), and
> found this:
>
> void *
> pthread_getspecific (pthread_key_t key)
> {
> int lasterror = GetLastError();
>
> void *ptr = TlsGetValue (key->key);
>
> SetLastError( lasterror );
>
> return ptr;
> }
>
> I guess someone already found out TlsGetValue() clears out the last error, but
> they did not know it also clears out the last Winsock error. The fix is to
> change the code to:
>
> void *
> pthread_getspecific (pthread_key_t key)
> {
> int lasterror = GetLastError();
> int lastWSAerror = WSAGetLastError();
>
> void *ptr = TlsGetValue (key->key);
>
> SetLastError( lasterror );
> WSASetLastError( lastWSAerror );
>
> return ptr;
> }
>
> I have added a work around to HawkNL until this gets fixed.
>
> Phil Frisbie, Jr.
> Lead Developer, Hawk Software
> http://www.hawksoft.com
--
+-------------------------+---+
| Ross Johnson | | "Come down off the cross
| Management & Technology |___| We can use the wood" - Tom Waits
| Building 11 |
| University of Canberra | eMail: rpj@ise.canberra.edu.au
| ACT 2601 | WWW:
http://public.ise.canberra.edu.au/~rpj/
| AUSTRALIA |
+-----------------------------+