Standard way to make STL objects thread safe?

I need some thread safe STL containers.

Basically, I thought that I just needed to add two methods to each of the objects in the STL container,

.lock()

.unlock()

I could also break it into

.lockForReading()
.unlockForReading()
.lockForWriting()
.unlockForWriting()

The way this works is any number of locks for parallel reading, it is permissible, but if there is a lock for writing, then reading and writing are blocked.

An attempt to lock to write waits until the lockForReading semaphore drops to 0.

Is there a standard way to do this?

How do I plan to do this wrong or short-sighted?

+3
source share
4 answers

- . , RAII. ,

.lock()

.unlock()

. , .

Boost.Thread , boost::mutex::scoped_lock. lock() unlock() , , boost:mutex boost::mutex::scoped_lock .

+5

. , .

. , . , , , , . , .

, . , . , , .

+5

?

, .

?

-, ( DeadMG : ..).

, TBB concurrent_vector , "" .

, () Lock (, ), 2 3 , , .

+2

Sam: .lock(), - , .unlock() , .unlock() , , .lock().

DeadMG: Intel ( ) .

There is also a Microsoft concurrent_vector and concurrent_queue , which already comes with Visual Studio 2010.

-1
source

All Articles