Is errno
on MSVC thread-safe?
According to the answers in this question POSIX requires that errno
is thread-safe. But MSVC is probably not
I can't find anywhere on the MSDN site where this is discussed. However, many functions which returns static buffers are already thread safe in MSVC (i.e. they return pointers to thread local buffers). So it'd be surprising if errno wasn't thread safe.
The MSVC header files all have this definition:
#ifndef _CRT_ERRNO_DEFINED
#define _CRT_ERRNO_DEFINED
_CRTIMP extern int * __cdecl _errno(void);
#define errno (*_errno())
errno_t __cdecl _set_errno(_In_ int _Value);
errno_t __cdecl _get_errno(_Out_ int * _Value);
#endif /* _CRT_ERRNO_DEFINED */
And a small test program showd that 2 threads setting errno did at least not affect eachother. So I'd say it's safe to assume errno is thread safe (though probably not if you link to the single thread CRT)