Re: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
Re: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
- Subject: Re: Why am I not getting per-thread errno? (was Re: Spurious EBADF?)
- From: Vincent Lubet <email@hidden>
- Date: Tue, 19 Nov 2002 10:46:38 -0800
That's a problem that recently, the main thread always uses the global
errno instead of the per-thread errno (Radar # 3080082)
I don't know if there's a simple workaround.
Vincent
On Monday, November 18, 2002, at 02:58 PM, Avi Drissman wrote:
At 11:16 PM +0000 11/13/02, Quinn wrote:
Is your code threaded?
Yes. That's the problem. I need help fixing it.
errno is #defined as:
#define errno (*__error())
What is __error()? When in doubt, check into Darwin. At
<http://www.opendarwin.org/cgi-bin/cvsweb.cgi/src/Libc/sys/
errno.c?rev=1.1.1.1&content-type=text/x-cvsweb-markup> we see:
extern int errno;
int *__error(void) {
pthread_t self = pthread_self();
/* If we're not a detached pthread, just return the global errno
*/
if ((self == (pthread_t)0) || (self->sig != _PTHREAD_SIG) ||
(self->detached & _PTHREAD_CREATE_PARENT)) {
return &errno;
}
return &self->err_no;
}
Tracing through this, I see that self is non-null, and does have the
signature. However, the _PTHREAD_CREATE_PARENT bit is set for
self->detached. (In fact, self->detached is 0x5, and
pthread_internals.h doesn't mention what that other bit means.)
Therefore, instead of getting the thread-safe errno, I get the
non-thread safe errno.
Then, I'm sure I'm getting a real error (likely EWOULDBLOCK), but due
to some race condition, someone smashes my errno value with some
garbage, I see the bad value, and kill the connection, much to the
surprise of the client.
How do I make my errno thread-safe?
Avi
--
Avi 'rlwimi' Drissman
email@hidden
Argh! This darn mail server is trunca
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.