This is the mail archive of the
libstdc++@gcc.gnu.org
mailing list for the libstdc++ project.
STL, thread-safety and iterators
- From: Kalaky <kalaky at gmail dot com>
- To: libstdc++ at gcc dot gnu dot org
- Date: Thu, 14 Sep 2006 22:36:28 -0300
- Subject: STL, thread-safety and iterators
Hi,
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 ?
For example:
slist<struct foo> list;
thread A:
lock();
list.insert_after(list.begin(), elem);
unlock();
thread B:
lock();
const_iterator it = slist.begin();
const struct foo& elem = *it;
unlock();
// operations on elem are atomic
while (bar) { foo.i++ | *it.i++ }
lock();
slist.erase(it);
unlock();