STL slist/map containers concurrent/thread-safe access

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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();
// or
iterator it = slist.begin();

const struct foo& elem = *it;
// or
struct foo& elem = *it'
unlock();

// operations on elem are atomic

while (bar++) {
foo.i++ | *it.i++
// or
if (foo.i == 5)
 foobar();
}

lock();
slist.erase(it);
unlock();

[Index of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux