This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]