
Le 21/02/13 14:05, Igor R a écrit :
Hello,
Just wanted to be sure that I'm doing this correctly.
typedef boost::upgrade_lockboost::shared_mutex upgrade_lock; typedef boost::upgrade_to_unique_lockboost::shared_mutex upgrade_to_unique_lock;
upgrade_lock readLock(mutex_); // accessing shared resources in read-only mode //... upgrade_to_unique_lock writeLock(readLock); // modifying shared resources
Is the above correct? In particular, upgrade_lock acquires "read" lock in raii style (similarly to shared_lock), right?
Even if currently shared_mutex and upgrade_mutex implementation is the same you should use upgrade_mutex. Otherwise the code seems correct. You have shared access in [1] and [2] and unique access in [2]. typedef boost::upgrade_lockboost::upgrade_mutex upgrade_lock; typedef boost::upgrade_to_unique_lockboost::upgrade_mutex upgrade_to_unique_lock; boost::upgrade_mutex mutex_; { upgrade_lock readLock(mutex_); // [1] accessing shared resources in read-only mode //... { upgrade_to_unique_lock writeLock(readLock); // [2] modifying shared resources } // [3] accessing shared resources in read-only mode } Best, Vicente