I saw a piece of code like this and wondered whether this is thread-safe:
int savedErrno = errno;
//call some function that may modifies errno
if (errno == xxx)
foo();
errno = savedErrno;
I don’t think this is thread-safe, am I correct?
But I saw people write code like this, so I am not sure…
Can any one help me clarify this, thanks…
Each thread has its own (thread specific) copy of errno so that looks like it should be safe.
From man (3) errno: