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?
source
share