自定义Lock
class ReadLock {
public:
ReadLock(ZoneFile* zfile) : zfile_(zfile) {
zfile_->writer_mtx_.lock();
zfile_->readers_++;
zfile_->writer_mtx_.unlock();
}
~ReadLock() { zfile_->readers_--; }
private:
ZoneFile* zfile_;
};
class WriteLock {
public:
WriteLock(ZoneFile* zfile) : zfile_(zfile) {
zfile_->writer_mtx_.lock();
while (zfile_->readers_ > 0) {
}
}
~WriteLock() { zfile_->writer_mtx_.unlock(); }
private:
ZoneFile* zfile_;
};
标签:Multi,Thread,ZoneFile,writer,mtx,C++,_.,_-,zfile
From: https://www.cnblogs.com/attack204/p/16823715.html