要点:
1 boost提供了如下lock模板类,以mutex类型作为模板参数
- Class template
lock_guardClass template unique_lockClass template shared_lockClass template upgrade_lockClass template upgrade_to_unique_lockMutex-specific class scoped_try_lock2 boost提供了如下mutex类型,分别用于上面的lock模板类的参数
- Class
mutexTypedef try_mutexClass timed_mutexClass recursive_mutexTypedef recursive_try_mutexClass recursive_timed_mutexClass shared_mutex- Class
condition_variableClass condition_variable_anyTypedef condition4 仅初始化一次问题
#include <boost/thread/once.hpp>
boost::once_flag f=BOOST_ONCE_INIT;
template<typename Callable> void call_once(once_flag& flag,Callable func);
void call_once(void (*func)(),once_flag& flag);两个函数,一个flag,用于程序中仅调用一次func
5 Barriers
class barrier { public: barrier(unsigned int count); ~barrier(); bool wait(); };
障碍是一个同步点,在wait的地方,必须count个线程都执行到该位置,才开始wait后面的内容;
6 futures
应用场合是:一个线程发出命令,另外一个线程执行命令,发出命令线程通过future获得命令的执行结果;详细内容参考分布式网络编程内容《面向模式的软件体系结构卷2》
相关的类有boost::promise or a
boost::packaged_task;
总结,同步内容很多,详细参考boost文档;该内容很实用;
Boost库的同步与并发技术概述
本文概要介绍了Boost库中的同步与并发组件,包括互斥锁、条件变量、屏障、未来等概念,以及如何解决仅初始化一次问题。
6800

被折叠的 条评论
为什么被折叠?



