It needs to #include <errno.h> to get the macro definition of errno in
<sys/errno.h>. I'm surprised this test isn't broken on more platforms.
Actually, that's not causing the problem the OP is seeing. <errno.h>
gets included by <pthread.h>, which causes errno to be defined as:
#define errno (*__error())
The problem is in the implementation of __error():
#undef 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;
}
Libc has both global and per-thread errno values, which both get set on
return from a failed library call. The self->detached check above is
true in the case of the main thread, so the main thread always uses the
global errno value, and the global errno value is always set at the
same time the per-thread value is set.
While the window for this race *should* be small (programs are supposed
to only check errno immediately after a failed library call), I've
filed a bug against the "optimization" in the __error()
implementation...
matt.
_______________________________________________
unix-porting mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/unix-porting
Do not post admin requests to the list. They will be ignored.