This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: STL slist/map containers concurrent/thread-safe access
- From: John Love-Jensen <eljay at adobe dot com>
- To: Kalaky <kalaky at gmail dot com>, MSX to GCC <gcc-help at gcc dot gnu dot org>, <gcc at gcc dot gnu dot org>
- Date: Fri, 15 Sep 2006 06:43:22 -0500
- Subject: Re: STL slist/map containers concurrent/thread-safe access
Hi Kalaky,
#1. Please do not cross post to GCC-help and GCC lists.
#2. GCC@gcc.gnu.org is not an appropriate forum for your question.
#3. GCC-Help@gcc.gnu.org is not an appropriate forum for your question.
#4. Your question is a general C++ question, not a GCC question.
> Given that removing/inserting elements from a map/slist/whatever does
> not invalidate iterators to list elements, it is safe to use the
> element that the iterator "points" to ?
The rules for iterator invalidation are tightly dependent on the container
involved. I recommend reading the ISO 14882 standard very carefully about
what STL containers guarantee about their iterators. (I always have to look
them up myself -- I tend to pessimistically over-assume that my iterators
are invalidated more often then they really are in actuality.)
I'm pretty sure that removing an element from a container will cause any
iterator pointing to that element to become invalidated, for all containers.
How do you have an iterator to an element in a container, when that element
hasn't been inserted into the container yet?
*AFTER* an element is inserted into a container, and then you acquire an
iterator to that element, I presume that iterator properly refers to that
element.
I recommend you use a "Safe STL" for your development. It will help you
discover problematic STL usage in your code.
Here are some "safe STL" implementations:
http://www.horstmann.com/safestl.html
http://www.stlport.org/
http://gcc.gnu.org/onlinedocs/libstdc++/debug.html
Good luck!
--Eljay