![](/img/trans.png)
[英]Is boost::fast_pool_allocator using null_mutex safe in the presence of allocator rebinding?
[英]boost::details::pool::pthread_mutex and boost::details::pool::null_mutex
boost::details::pool::pthread_mutex
和boost::details::pool::null_mutex
之间有什么boost::details::pool::null_mutex
?
我看到在最新的Boost版本-1.42中,类boost::details::pool::pthread_mutex
被删除。 我应该怎么用呢?
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线程库(如果您的系统使用pthread,它将是基于pthread的互斥体)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.