Boost logo

Boost Users :

From: Igor R (boost.lists_at_[hidden])
Date: 2008-06-15 12:14:30


> But I can't say the same things for non-const function which returns reference. <...> And also iterators are same as the index operator, not thread safe.

It seems that the only way to use such a container in the thread-safe
manner, is to perform all the necessary locking at some higher-level
of your design.
Besides the problem you mentioned, you've got another issue: usually
you wish to get not just "physical" thread-safety (meaning that your
container remains in a consistent state), but a "logical" one.
Consider the following code:

if (myVector_.size())
{
 Element element = myVector_[0];
}

It doens't make sense that size() and operator[]() themselves are
"thread-safe", as between these calls the size might change. This
means that the user of your container has to lock it anyway. If so,
your internal locking appears to be useless overhead.


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net