Are std::list std::vector std::map thread-safe class?
-
Two thread access a std::list object, either of two will add to/(delete) the std::list. When make critical section or mutex guard, I know can make the std::list safe. But does std::list itself implemented thread-safe? Thanks advanced for helping unlock my mind!
-
Two thread access a std::list object, either of two will add to/(delete) the std::list. When make critical section or mutex guard, I know can make the std::list safe. But does std::list itself implemented thread-safe? Thanks advanced for helping unlock my mind!
You failed to mention which implementation of STL you are using as there are several available. These include SGI-STL, STLPort, Dinkumware and other minor vendors. There are some slight differences in how each handle concurrency. With that being said, the C++ standards do not make any guarantees about thread safety with iterator reading/writing to std::list from multiple threads. This essentially means that it is up to the software engineer to ensure thread-safety. Best Wishes, -David Delaune
-
You failed to mention which implementation of STL you are using as there are several available. These include SGI-STL, STLPort, Dinkumware and other minor vendors. There are some slight differences in how each handle concurrency. With that being said, the C++ standards do not make any guarantees about thread safety with iterator reading/writing to std::list from multiple threads. This essentially means that it is up to the software engineer to ensure thread-safety. Best Wishes, -David Delaune
Really thank you. You do me a big favor!