Hacker News new | ask | show | jobs
by jcotton42 510 days ago
It's not just libc, it's any C or C++ library that calls getenv or setenv.
1 comments

Specifically, any C or C++ library that calls setenv (despite documentation that says that setenv is not threadsafe).
Or any multithreaded program that uses a C or C++ library that calls setenv somewhere internally, and failed to document that it does so and is thus unsuitable for use by multithreaded programs.

No library does that documentation, so you can't use libraries on POSIX systems if writing multithreaded code. Or you do and hope for the best. So everyone just hopes for the best.

The documentation for setenv:

   Caveats: POSIX.1 does not require setenv() or unsetenv() to be reentrant.

   ...
   Interface: setenv(), unsetenv() 
   Attribute: Thread safety
   Value:  MT-Unsafe const:env

Libraries that are thread-safe DO provide that documentation. One assumes that libraries that don't provide that documentation are not thread=safe.

GnuTLS docs: The GnuTLS library is thread safe by design, meaning that objects of the library such as TLS sessions, can be safely divided across threads as long as a single thread accesses a single object.