Are boost interprocess containers suitable for thread shared storage in the same process?
I need a vector container to be shared between two threads of the same process, providing mutex protected access for the following met开发者_C百科hods:
empty
size
erase
push_back
I would also like the collection to provide an iterator which locks the container while the iterator is in use. Essentially I am looking for a collection with a std::vector<...>
interface but with concurrent access protection but I can't seem to find anything.
Are the boost::interprocess
containers suitable for this application? If not, is there an alternative which is more suitable or do I have to write my own?
The answer is yes - it is suitable. See here
If boost::interprocess
containers don't work out, it may be worth looking into Intel TBB. I've started using it recently and have been very pleased. Specifically, check out tbb::concurrent_vector
.
精彩评论