(1) 基于boost的生产者/消费者队列

template<typenameData>
classconcurrent_queue { private: std::queue<Data> the_queue; mutableboost::mutex the_mutex; boost::condition_variable the_condition_variable; public: void push(Data const& data) { boost::mutex::scoped_lock lock(the_mutex); the_queue.push(data); lock.unlock(); the_condition_variable.notify_one(); } bool empty() const { boost::mutex::scoped_lock lock(the_mutex); returnthe_queue.empty(); } bool try_pop(Data& popped_value) { boost::mutex::scoped_lock lock(the_mutex); if(the_queue.empty()) { returnfalse; } popped_value=the_queue.front(); the_queue.pop(); returntrue; } void wait_and_pop(Data& popped_value)
{ boost::mutex::scoped_lock lock(the_mutex); while(the_queue.empty()) { the_condition_variable.wait(lock); } popped_value=the_queue.front(); the_queue.pop(); } };

  

CUtilityCode的更多相关文章

随机推荐

  1. CSS3动画里的过渡效果

    过渡效果中有: 1平滑效果 2线性过渡 3由慢到快 4由快到慢 5慢-快-慢  等等 具体参考 w3chool 例如: <body> <div class="out&quo ...

  2. JAVE not work in linux

    1, it will print out exception, but still can convert the audio 2, it works in windows not linux, ne ...

  3. iOS @@创建NSURL的字面量

    @@ 是创建 NSURL 的字面量的绝佳方法(例如:@@"http://example.com")

  4. 开源协议:LGPL协议、OSGi协议---打酱油的日子

    本文介绍开源的协议. LGPL 是 GNU Lesser General Public License (GNU 宽通用公共许可证)的缩写形式,旧称 GNU Library General Publi ...

  5. jquery:closest和parents的主要区别

    closest和parents的主要区别是:1,前者从当前元素开始匹配寻找,后者从父元素开始匹配寻找:2,前者逐级向上查找,直到发现匹配的元素后就停止了,后者一直向上查找直到根元素,然后把这些元素放进 ...

  6. [python学习] 语言基础—排序函数(sort()、sorted()、argsort()函数)

    python的内建排序函数有 sort.sorted两个. 1.基础的序列升序排序直接调用sorted()方法即可 ls = list([5, 2, 3, 1, 4]) new_ls = sorted ...

  7. Jquery_类选择器笔记

    $("[id^=percent]").size() ^=:表示以什么开头 $=:表示以什么结尾 ~=:表示包含什么 id:表示按id选择

  8. EaseMode

    The following graphs demonstrate the different values of EasingMode, where f(t) represents the anima ...

  9. Ext之ExtGrid增删改查询回顾总结

    学习Ext已经有些许时间了,发现实际运用过程中ExtGrid系列还是最为常用的,本来想自己写些话语来总结的,无意间看到有位仁兄早就总结了,故冒犯贴在此处,以便以后翻阅,还望见谅 Ext - Grid  ...

  10. Bigtable 论文 阅读笔记 - 原理部分

    不支持markdown,桑心.更好的阅读体验请看:Github/Bigtable.md Paper: Google Bigtable paper Notes author: Lhfcws Wu Tim ...