[boost-users][thread] upgrading lock
Hello, This's rather basic question, but I couldn't find any example in the docs. typedef boost::shared_lockboost::shared_mutex shared_lock; shared_mutex mutex_; /// { shared_lock lock(mutex_); // reading locked data... // here I want to midify the data, how can I upgrade the lock to be exclusive? } Thank you in advance.
"Igor R"
This's rather basic question, but I couldn't find any example in the docs.
typedef boost::shared_lockboost::shared_mutex shared_lock; shared_mutex mutex_; /// { shared_lock lock(mutex_); // reading locked data...
// here I want to midify the data, how can I upgrade the lock to be exclusive? }
You can't change a shared_lock to an unique_lock. If you want to do
this, use an upgrade_lock. There can be at most one upgrade_lock held
at any one time on a shared_mutex, but an upgrade_lock can share
ownership with any number of shared_locks. You can then upgrade the
lock by transferring ownership from the upgrade_lock to a unique_lock:
{
upgrade_lock
participants (2)
-
Anthony Williams
-
Igor R