|
|
None of the thread management or synchronization routines in the Threads Library set errno to indicate an error; most return an error number if an error is encountered.
However, threads may call routines that do set errno. If all threads in a process accessed a global errno, no thread could be sure that the global value resulted from a system call it had made, it might have resulted from another system call made by another thread. Therefore, the Threads Library maintains a private copy of errno for each thread. When a thread references errno, it will get the value of its private copy, not the global variable.
There is one exception: the initial thread (the thread running main) accesses the global errno via its private copy. Therefore, the initial thread can safely call into non-reentrant code (such as an old object file compiled before SVR4.2MP and SCO OpenServer), and have correct errno semantics. Threads other than the initial thread should not make calls into old object files that set errno. The mixing of reentrant and non-reentrant object files is discouraged, and should only be done as an interim measure until applications are made reentrant.