(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. Daily Scrum Meeting ——EighthDay

    一.Daily Scrum Meeting照片 橙汁参加ICPC未归,周一牛姐去上课,佳恺今天去迎新晚会表演舞台剧了 二.Burndown Chart 今日没有燃掉issues 增添了两个issue ...

  2. iOS中类别的使用

    类别的三大作用1.给现有的类增加方法,可以增加 对象方法,也可以增加静态方法. 如果增加的方法是此类本来就有的方法,那么,此方法有可能会把原方法覆盖,也有可能不会覆盖. 类别只能增加现有类的方法,不能 ...

  3. 08 Servlet

    Servlet技术          * Servlet开发动态的Web资源的技术.                       * Servlet技术               * 在javax. ...

  4. TodoMVC中的Backbone+MarionetteJS+RequireJS例子源码分析之二 数据处理

    当我们使用jQuery时大部分时间是聚焦于Dom节点的处理,给Dom节点绑定事件等等:前端mvc框架backbone则如何呢? M-Model,Collection等,是聚焦于数据的处理,它把与后台数 ...

  5. 1.1 Quartz 2D 绘图

    本文并非最终版本,如有更新或更正会第一时间置顶,联系方式详见文末 如果觉得本文内容过长,请前往本人 “简书”   Quartz2D 绘图主要步骤:   1. 获取[图形上下文]对象 —— (拿到草稿纸 ...

  6. Excel大批量导入数据到SQLServer数据库-万条只用1秒

    private string ExcelToStudent() { /*---*/ var preStr = DateTime.Now.ToString("yyyyMMddHHmmssfff ...

  7. ZeroMQ接口函数之 :zmq_socket_monitor - 注册一个监控回调函数

    ZeroMQ 官方地址 :http://api.zeromq.org/4-2:zmq-socket-monitor zmq_socket_monitor(3) ØMQ Manual - ØMQ/4.1 ...

  8. JS创建缩略图

    <script language="javascript"> //显示缩略图 function DrawImage(ImgD,width_s,height_s){ /* ...

  9. DB Connection String

    SQL: Data Source=APGZDB04;Initial Catalog=ChinaEDI;Persist Security Info=True;User ID=edi_ac;Passwor ...

  10. HDU 1166 敌兵布阵(分块)

    敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submi ...