CUtilityCode
(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的更多相关文章
随机推荐
- TComboBox; 指定某一行,不给下拉,只读ReadOnly 伪装 实现
//cbb1: TComboBox; 指定某一行,不给下拉,自读伪装 实现: cbb1.Style :=csSimple; //设定style 不可以下拉 cbb1.ItemIndex := ; // ...
- 双系统win+ubuntu无法访问win的盘符
1.打开终端:如果没有安装ntfs-3g就要安装: sudo apt-get install ntfs-3g 2.修复挂载错误的相应的分区: sudo ntfsfix /dev/sda(×) (×)取 ...
- zeromq中两个dealer 通过一个router进行通信
发现有童鞋不是很清楚ZMQ中的“请求-回复”模式中的ROUTER怎么用,所以简单介绍一下“请求-回复”模式的使用(最后付代码). 一.讲一讲 1.要使用zmq 通过一个router进行通信,你首先需要 ...
- &与&&,|与||
http://bokeid.blog.163.com/blog/static/93102786201181710259178/ &&:逻辑运算符,连接两个或多个表达式,结果为TRUE或 ...
- c#操作xml文件(XmlDocument,XmlTextReader,Linq To Xml)
主界面
- Mac 系统环境变量配置
Mac 系统环境变量配置 例如这里要配置一下 QUICK_V3_ROOT 的环境变量 1.打开终端 输入 vim ~/.bash_profile 2.一直回车 知道出现以下选项 按 E 编辑 ...
- Unity学习疑问记录之触屏
当将Unity游戏运行到ios或android设备上时,桌面系统中的鼠标左键操作可以自动变为手机屏幕上的触屏操作,但鼠标操作无法实现一些特有的触屏操作,比如多点触屏. 触控对于Android移动设备来 ...
- 转:Egret社区翻译的《TypeScript语言手册》
<TyptScript语言手册>第1章-介绍<TypeScript语言手册>第2章-基本概念<TypeScript语言手册>第3章-类型<TypeScri ...
- 关于thinkphp开发的几种规范(仅限个人)
一.只要设计到where查询语句,无论是增删改查 $cn['username'] = session('member.username'); $cn['itemid'] = $itemid; $ite ...
- Apache2 worker
http://www.php-internals.com/book/?p=chapt08/08-03-zend-thread-safe-in-php 在多线程系统中,进程保留着资源所有权的属性,而多个 ...