1753666 Members
6054 Online
108799 Solutions
New Discussion

STL Using Threads

 
SOLVED
Go to solution
ivano_1
New Member

STL Using Threads

Looking at aC++ online programmers guide (A06.05) it seems that the stl library (v2) are thread safe (-mt switch), but using from multiple threads the same queue object with push and pop calls the program ended, however if we protect the calls via mutex the program complete succesfully. Looking inside the template code there are no mutexes, this make me thing that the STL are not thread safe.
Any comment? Thanks and regards, Ivano
1 REPLY 1
Dennis Handly
Acclaimed Contributor
Solution

Re: STL Using Threads

STL containers are only thread safe behind the user's back. (In particular the reference counted strings.)

But the user is responsible synchronizing his own accesses and modifications to his containers. The same as if you were dealing with an int.

Accessing separate STL containers is safe.