|
Boost Users : |
Subject: Re: [Boost-users] upgrading lock
From: Vicente J. Botet Escriba (vicente.botet_at_[hidden])
Date: 2013-02-21 13:33:43
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_lock<boost::shared_mutex> upgrade_lock;
> typedef boost::upgrade_to_unique_lock<boost::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_lock<boost::upgrade_mutex> upgrade_lock;
typedef boost::upgrade_to_unique_lock<boost::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
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net