4

Possible Duplicate:
Do I need to protect read access to an STL container in a multithreading environment?

I am using the C++ standard library which comes with (Linux) GCC or (Windows) VC.

Can anyone please say clearly whether or not this library is thread safe?

Community
  • 1
  • 1
User7723337
  • 11,857
  • 27
  • 101
  • 182
  • It isn't. Unless stated otherwise. You can find all of that in documentation like http://cppreference.com or the [standard specification](http://www.open-std.org/jtc1/sc22/wg21/) – sehe Jan 02 '13 at 13:12
  • 2
    http://kera.name/articles/2010/08/it-is-not-called-the-stl-mmkay/ – Griwes Jan 02 '13 at 13:14
  • As often the answer is "that depends". For the containers of the C++ standard library you will find helpful information about "thread safety" here: https://en.cppreference.com/w/cpp/container – Sonic78 Jan 17 '23 at 15:23

1 Answers1

3

"Thread safe" is not a clearly-defined boolean property of a library. Some things can be done concurrently and others cannot.

Almost certainly if you were to ask a more detailed question specifying what it is you want to do, the answer would be "no, it is not thread-safe". But only almost.

If by "thread-safe" you mean something like the difference between Vector and ArrayList in Java, then C++ standard containers are non-thread-safe.

Steve Jessop
  • 273,490
  • 39
  • 460
  • 699