(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. json-lib——JsonConfig详细使用说明

    在使用json-lib包中JSONObject.fromObject(bean,cfg)时,可能出现以下几种情况: 1.(防止自包含)转换的对象包含自身对象,或者对象A下面挂了对象B,对象B下面又挂了 ...

  2. UVA 12544 - Beehives O(nm) 无向图最小环

    Bees are one of the most industrious insects. Since they collect nectarand pollen from flowers, they ...

  3. 网站开发常用cmd命令

    一.Windows服务安装: framework 4.0 : cd C:\Windows\Microsoft.NET\Framework\v4.0.30319 framework 2.0 :  cd ...

  4. UI--普通控件总结1--控件使用

    本文目录 0.UIView常用的属性和操作 0_1.UIView常见的属性 0_2.UIView状态 0_3.UIView常用的方法 1.文本框UITextField和文本视图UITextView 1 ...

  5. ImageLoader

    配置ImageLoader 一般我们在使用ImageLoader的时候,需要在应用程序的入口进行它的一个配置,这个配置一般写到Application里边 * public void initImage ...

  6. GregorianCalendar类

    Calendar类实现了公历日历,GregorianCalendar是Calendar类的一个具体实现. Calendar 的getInstance()方法返回一个默认用当前的语言环境和时区初始化的G ...

  7. CSS3初学篇章_7(布局/浏览器默认样式重置)

    CSS布局说到布局,就不得不提布局的核心<div>标签,它与其它标签一样,也是一个XHTML所支持的标签,专门用于布局设计的容器标签.在css布局方式中,div 是这种布局方式的核心对象, ...

  8. c#向数据库插入较大数据(SqlBulkCopy)

    因为要向数据库添加一些数据,数据量较大 1.使用sql语句批量提交速度较慢 2.用事物批量提交,速度一般 3.用SqlBulkCopy方法写入数据,速度较快 /// <summary> / ...

  9. 文本编辑器VIM/VI

    vim/vi  功能强大全屏文本编辑器.主要是建立,编辑,显示文本. www.vim.org  构建shell脚本 :set number 使文件出现行号 a 光标后附件文件     i在光标前插入文 ...

  10. opencv的问题

    opencv中图像文件格式是BRG的顺序 而QImage是RGB形式 H:色彩 S:深浅 s=0 只有灰度 V:明暗