2 ms·
I remember years ago having to port some C code I wrote to AIX. Hit this really weird bug - on AIX, errno is not thread-safe by default! Solution is simple: a
by skissane 4y ago
I remember years ago having to port some C code I wrote to AIX.
Hit this really weird bug - on AIX, errno is not thread-safe by default!
Solution is simple: add -D_THREAD_SAFE or -D_THREAD_SAFE_ERRNO to CFLAGS. Took me a few hours of scratching my head before I worked it out though.
- lelanthran 4y ago> Hit this really weird bug - on AIX, errno is not thread-safe by default! Isn't that a conforming implementation? (IIRC[1], errno is thread-local, not necessarily race-safe. i.e. it's visible to interrupts, which could change it) [1] No doubt someone will correct me if that is wrong.
- jabl 4y agoMany old-school unixes were developed in the single-thread days. When they added support for threads they were an opt-in feature, like the above macro definitions, and using libraries like libc_r.so instead of libc.so, and so on. AIX even had compiler wrappers like xlc_r which set the relevant preprocessor macros and linked in the correct runtime libraries. When the Linux glibc 2.x/NPTL ABI was taken into use, it was clear that threads were not a passing fad and stuff was made multi-thread (to the extent the API can enable that, of course) by default, so there was no need for carrying around both a single-thread ABI and a multi-thread ABI.
- skissane 4y ago> IIRC[1], errno is thread-local, not necessarily race-safe. i.e. it's visible to interrupts, which could change it) On AIX, errno is not thread-local by default, it is a global variable shared by all threads. Only if you set one of those two defines, does it become a thread-local variable. On every other platform I’ve ever written code for, errno is thread-local by default and no special define is needed to make it so. Hence, when you port to AIX, if you don’t know about those defines, you can get all these weird race condition bugs related to error handling, because suddenly errno isn’t thread-local any more