Subj : Re: How to deal with errno in a multipthread program To : comp.programming.threads From : Eric Sosman Date : Fri Apr 15 2005 12:49 pm icoming wrote: > Is it enough to deal with it as follow: > int err=errno; > func(); //this function may modify the errno > errno=err; > I read W.Richard Stevens's UNIX Network Programming, it uses this way, > but I do not think it's enough, but do not know there is better one. This is appropriate when you want to preserve the errno value within a single thread, preventing func() from changing it (or rather, repairing whatever changes func() may have made). It really has nothing to do with threads. However, you do not need to worry. The thread implementation itself arranges to have a unique `errno' for each thread: Threads T1 and T2 can simultaneously store different values in errno, and this works because the single name `errno' refers to a different memory location for each thread. Different implementations achieve this rather magical effect in different ways, but the outcome is that "it just works." In a threaded program there is no such thing as "the stack" or "the program counter;" there are multiples, one for each thread. Similarly with "the errno variable;" each thread has its own. -- Eric.Sosman@sun.com .