-
Boost Read/Write Mutexes
[Mod note: Split from here]
I have worked with boost::shared_mutex and boost::shared_lock, boost::unique_lock as specified to acieve multiple readers single writer.
Unfortunately I found out that when writer is working Boost does not allow reader access EVEN the reader is from the SAME thread!
And vice versa, When reader is working, Boost does not allow writer access EVEN the writer is from the SAME thread!
I just want to mention that this scenario is of course possible.
For instance, if there is a big block of code - read protected. Inside this block there is a small general routine that need a write access.
I don't want to change the whole code block to write access since it unnecessarily prevents other readers to run when it it possible to do so.
Closing the reader before writer starts and reopening it after the writer finish cause too much overhead.
Is there any answer within boost framework to this scenario?
Zafrir Patt 11/6/09
-
That's what upgradeable locks are for. However, notice that only one upgradeable reader is possible at any one time (shared with any number of pure readers).
I've split this into a new thread. Please start new threads for new questions.