I have a multithreaded app that has to read some data often, and occasionally that data is updated. Right now a mutex keeps access to that data safe, but it's expensive because I would like multiple threads to be able to read simultaneously, and only lock them out when an update is needed (the updating thread could wait for the other threads to finish).
I think this is what boost::shared_mutex
is supposed to do, but I'm not clear on how to use it, and haven't found a clear example.
Does anyone have a simple example I could use to get started?
Best Answer
1800 INFORMATION is more or less correct, but there are a few issues I wanted to correct.
Also Note, unlike a shared_lock, only a single thread can acquire an upgrade_lock at one time, even when it isn't upgraded (which I thought was awkward when I ran into it). So, if all your readers are conditional writers, you need to find another solution.