boost::details::pool::pthread_mutex
和boost::details::pool::null_mutex
之间有什么区别。
我看到在最新的升级版本 - 1.42中,类boost::details::pool::pthread_mutex
被删除了。我该怎么用?
答案 0 :(得分:1)
boost::details::pool::null_mutex
是一个什么都不做的互斥锁(锁总是立即成功)。当你不使用线程时这是合适的。 Boost池库根据boost\pool\detail\mutex.hpp
中的以下片段选择将使用哪种互斥锁来将关键部分的访问权限与互斥锁类型的typedef同步:
#if !defined(BOOST_HAS_THREADS) || defined(BOOST_NO_MT) || defined(BOOST_POOL_NO_MT)
typedef null_mutex default_mutex;
#else
typedef boost::mutex default_mutex;
#endif
换句话说,如果配置说没有涉及线程(无论是整个Boost,还是特别是池库),那么将使用null_mutex
(基本上是一个nop)
如果要支持线程,那么将使用boost::mutex
类型,它来自Boost线程库(如果你的系统使用pthreads,它将是一个基于pthread的互斥锁)。