5

I know how to convert a string into int, float... is never a new question. After going through some articles, I was suggested to use strtol, strtoll, strtod, so I took a close look at those functions.

Although strtol claims thread safety in its man page, but it will modify errno, so does it really thread safe?

If not, what's the right way to do such converting jobs in C++ (not C++11) and keep thread safe?

coinsyx
  • 643
  • 2
  • 7
  • 13

2 Answers2

4

From the errno man page:

errno is defined by the ISO C standard to be a modifiable lvalue of type int, and must not be explicitly declared; errno may be a macro. errno is thread-local; setting it in one thread does not affect its value in any other thread.

A function that sets errno will only set it for a single thread, so it's thread-safe.

user2357112
  • 260,549
  • 28
  • 431
  • 505
4

Yes they are, since errno itself is not a plain ordinary global variable: errno is thread-safe.

This is answered in Is errno thread-safe?.

Community
  • 1
  • 1
unwind
  • 391,730
  • 64
  • 469
  • 606