boost::details::pool::pthread_mutex and boost::details::pool::null_mutex

笑着哭i 提交于 2019-12-11 06:19:38

问题


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?


回答1:


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).



来源:https://stackoverflow.com/questions/10187966/boostdetailspoolpthread-mutex-and-boostdetailspoolnull-mutex

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!