After watching fefe and Erdgeist bash stupid APIs on the 26C3, I decided to also write/rant about such topics that I came across in the past. So here's the first one, from quite a while ago already...
I think you can safely say that most code these days should be multithread-aware, even if it doesn't feature threads itself. Older API-calls easily cause trouble since they are by design not reentrant - or at least their implementation isn't.
I understand that the programmer has to ensure his code is thread-safe. He has to know to call the right reentrant-variants of syscalls whenever possible. But what I experienced on Solaris really left me baffled.
Seems like on Solaris (at least V2.8 for SPARC), if you want to have certain system-library calls behave correctly in a multithreaded environment, you have to set the compiler(!) flag "_REENTRANT". Yes, you as a programmer have to tell the system header-files that you want them that you are planning to use them in a multithreaded environment!
But the best part: If you don't set that flag, you probably won't notice right away. I noticed when the errno-variable was always 0 in that case. So basically, it fucks up your error-handling - which you will only notice when things actually go wrong.
Solaris-Code reentrant
I think you can safely say that most code these days should be multithread-aware, even if it doesn't feature threads itself. Older API-calls easily cause trouble since they are by design not reentrant - or at least their implementation isn't.
I understand that the programmer has to ensure his code is thread-safe. He has to know to call the right reentrant-variants of syscalls whenever possible. But what I experienced on Solaris really left me baffled.
Seems like on Solaris (at least V2.8 for SPARC), if you want to have certain system-library calls behave correctly in a multithreaded environment, you have to set the compiler(!) flag "_REENTRANT". Yes, you as a programmer have to tell the system header-files that you want them that you are planning to use them in a multithreaded environment!
But the best part: If you don't set that flag, you probably won't notice right away. I noticed when the errno-variable was always 0 in that case. So basically, it fucks up your error-handling - which you will only notice when things actually go wrong.