boost锁介绍

boost thread库提供了三种级别的锁:

boost::shared_lock(读锁),boost::upgrade_lock(和读锁不互斥,与写锁、upgrade_loc互斥),boost::unique_loc(写锁)

五种互斥变量:

mutex:独占式互斥量

shared_mutex: 读共享/写互斥的共享互斥量

recursive_mutex: 递归互斥量

timed_mutex:超时独占互斥量

recursive_timed_mutex:超时递归互斥量

1.局部互斥锁(确保退出作用域时,释放锁)

#include <boost/thread/mutex.hpp>
boost::mutex mutex_;
boost::mutex::scoped_lock lock(mutex_);

2.读写锁

boost::shared_mutex wr_mutex_;
boost::shared_lock<wr_mutex_> read_lock_;//读锁
boost::unique_lock<wr_mutex_> write_lock_;//写锁


你可能感兴趣的:(boost锁介绍)