boost :: details :: pool :: pthread_mutex和boost :: details :: pool :: null_mutex [英] boost::details::pool::pthread_mutex and boost::details::pool::null_mutex
问题描述
boost::details::pool::pthread_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). /p>
如果要支持线程,则将使用boost::mutex
类型,该类型来自Boost线程库(如果您的系统使用pthread,它将是基于pthread的互斥体).
What is the differance between boost::details::pool::pthread_mutex
and boost::details::pool::null_mutex
.
I see that in latest boost version - 1.42, the class boost::details::pool::pthread_mutex
was deleted. What should I use instead?
boost::details::pool::null_mutex
is a mutex that does nothing (a lock always succeeds immediately). It's appropriate when you're not using threads. The Boost pool library selects what kind of mutex it will use to synchronize access to critical sections with a typedef for the mutex type based on the following snippet from boost\pool\detail\mutex.hpp
:
#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
In other words, if the configuration says that no threading is involved (either for Boost as a whole, or for the pool library in particular), then the null_mutex
will be used (which is basically a nop).
If threading is to be supported, then the boost::mutex
type will be used, which comes from the Boost thread library (and will be a pthread-based mutex if your system uses pthreads).
这篇关于boost :: details :: pool :: pthread_mutex和boost :: details :: pool :: null_mutex的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!