public inbox for pthreads-win32@sourceware.org
 help / color / mirror / Atom feed
From: "Phil Frisbie, Jr." <phil@hawksoft.com>
To: "pthreads-win32@sourceware.cygnus.com"
	<pthreads-win32@sourceware.cygnus.com>
Subject: Thread local storage problem, and fix
Date: Wed, 22 Aug 2001 11:51:00 -0000	[thread overview]
Message-ID: <3B83FF1D.DDB30CB0@hawksoft.com> (raw)

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

             reply	other threads:[~2001-08-22 11:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-08-22 11:51 Phil Frisbie, Jr. [this message]
2001-08-22 22:46 ` Ross Johnson
2001-08-23  0:41 ` Thomas Pfaff
2001-08-23  7:43   ` Phil Frisbie, Jr.
     [not found] <F0E13277A26BD311944600500454CCD034003B@antarctica.intern.net>
2001-08-27  2:05 ` Thomas Pfaff

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=3B83FF1D.DDB30CB0@hawksoft.com \
    --to=phil@hawksoft.com \
    --cc=pthreads-win32@sourceware.cygnus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).