你有关于这个问题的任何信息吗?特别是boost :: shared_mutex和读写器互斥的任何问题?
读写器互斥体可能被滥用,例如频繁的写入锁定会降低性能,即使与简单的互斥锁相比也是如此.但是很多情况下许多读者经常需要一个可以被编写者很少修改的共享资源.
我有一个可以从多个线程访问的类.getter和setter函数都有锁.是否需要用于吸气功能的锁?为什么?
class foo {
public:
void setCount (int count) {
boost::lock_guard<boost::mutex> lg(mutex_);
count_ = count;
}
int count () {
boost::lock_guard<boost::mutex> lg(mutex_); // mutex needed?
return count_;
}
private:
boost::mutex mutex_;
int count_;
};
Run Code Online (Sandbox Code Playgroud)