3

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,453
  • 24
  • 93
  • 160
  • 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

2 Answers2

3

See this video from Herb Sutter: https://web.archive.org/web/20170119232617/https://channel9.msdn.com/posts/C-and-Beyond-2012-Herb-Sutter-You-dont-know-blank-and-blank

wilx
  • 17,239
  • 5
  • 58
  • 112
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
  • 265,622
  • 35
  • 449
  • 690