site_archiver@lists.apple.com Delivered-To: darwin-dev@lists.apple.com Dkim-signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:received:received:message-id:date:from:sender :to:subject:cc:in-reply-to:mime-version:content-type:references :x-google-sender-auth; bh=qzyQ9mL63KmowBkIAmReC/YXLXHf8U80QgY0wCA5CUU=; b=evr4OAA8yDJn5KQhXky01cPKi68WYaqxhuRpGPC7CJjZYLQMvRl/Wdq+QGVqBaDgng 2LQml76HieRR2joGO4au/uMDgXZTrgXPOCsV1C4hnSEh6LvP65S9sgUBkuyxIE6RoQ2C 8Sp1c9YVDQ/ZaOg7VtwqdmaZ0q61S6ca2X7wk= Domainkey-signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=message-id:date:from:sender:to:subject:cc:in-reply-to:mime-version :content-type:references:x-google-sender-auth; b=jmKzxHO97Z7E6qUiYkvoPowMiZRssJFcUKoVySn8IHgOzYZTUBIc2CJiBCdRV+BSea WKT6s6g75i0Ij79Sb9R07G/LnJHCVXeRhO4dYkCXrQ2oVviL4HJGW4UuQlSaistyehoQ GEutuDYBYm+plHsG4S9gGGZIgmWHFJl2Lr4ZQ= Patrick- Below is the message from the list archive, I was referring to. Matt, everyone, Thanks very much for the help - and Matt, for filing the bug report. Scott On Sunday, October 20, 2002, at 10:33 PM, Matt Watson wrote: On Sunday, October 20, 2002, at 09:13 PM, Ian Lister wrote: #include <pthread.h> #include <stdio.h> #include <fcntl.h> #define errno (*__error()) The problem is in the implementation of __error(): _______________________________________________ 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. _______________________________________________ Do not post admin requests to the list. They will be ignored. Darwin-dev mailing list (Darwin-dev@lists.apple.com) Help/Unsubscribe/Update your Subscription: http://lists.apple.com/mailman/options/darwin-dev/site_archiver%40lists.appl... This email sent to site_archiver@lists.apple.com In the meantime, would a workaround be to redefine __error() (or a custom function) to just return &self->err_no, rather than checking to see if it's the main thread that's requesting it? On Sun, 20 Oct 2002, Scott D.W. Rankin wrote: 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: #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.