Re: [Boost-users] [boost.thread] thread safe circular_buffer implementation

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.
participants (1)
-
Igor R