How to implement a mulltiple read single write locker? This is the sample code by using boost shared_mutex. The other classes are using shared_lock, upgrade_lock and upgrade_to_unique_lock.
using namespace boost;
typedef boost::shared_mutex rwmutex;
typedef boost::shared_lock<rwmutex> readLock;
typedef boost::upgrade_lock<rwmutex> upgradeLock;
typedef boost::upgrade_to_unique_lock<rwmutex> writeLock;
rwmutex _rwmutex;
void readOnly() {
{
readLock rdlock(_rwmutex);
... do something ...
}
}
void writeOnly() {
{
upgradeLock lock(_rwmutex);
writeLock wLock(lock);
... do something
}
}
沒有留言:
張貼留言