Re: STL container read thread-safety.
On 4 avr, 17:26, "jason.cipri...@gmail.com" <jason.cipri...@gmail.com>
wrote:
I know that the overall thread safety of STL containers is not
guaranteed. However, if I have an std::vector<int> or an
std::list<int>, and multiple threads are reading them but
nothing is writing them, do I still need to synchronize access
to them?
What does your implementation say? I know that this is
supported by the STLport, the SGI implementations and to some
degree by g++, and I suspect that it is more or less universal,
but in the end, the standard doesn't say anything---yet---so all
you have are the guarantees of your implementation.
By "reading" I mean iterating through with const_iterators,
and also copying them to other containers with the assignment
operator.
What I mean is, am I guaranteed that, say, I don't know,
obtaining a const_iterator via std::list<int>::begin() isn't
doing any internal housekeeping or anything that would
potentially make it not thread- safe?
What about set and map?
The most wide spread convention is to extend the general Posix
rules to them, e.g. to make them obey the rules which apply to a
T[] under Posix. But as I said, the standard doesn't guarantee
it yet, so you'll have to check the documentation of your
implementation. (Good luck in finding it:-).)
--
James Kanze (GABI Software) email:james.kanze@gmail.com
Conseils en informatique orient=E9e objet/
Beratung in objektorientierter Datenverarbeitung
9 place S=E9mard, 78210 St.-Cyr-l'=C9cole, France, +33 (0)1 30 23 00 34