MSVC errno thread safety

前端 未结 2 1391
Happy的楠姐
Happy的楠姐 2021-01-04 14:26

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

2条回答
  •  攒了一身酷
    2021-01-04 14:51

    Although MSVC is definitely not POSIX compliant, errno is implemented in the MSVC runtime (at least as of MSVC2008) in a threadsafe manner.

    Although the documentation states that it is extern int errno it's actually implemented as a #define to a function which allows thread-safety to be imposed. If you step through this function in the disassembly window, it is clear that thread local storage is used.

    Sadly I can't point to any official documentation that confirms this but such is life!

提交回复
热议问题