boost::condition_variable、boost::time_wait使用方法
来源:互联网 发布:jing 软件 编辑:程序博客网 时间:2024/05/09 14:06
boost 的线程库不能强行终止,所以通过 time_wait 可以让其自然的结束。
// BoostTest.cpp : 定义控制台应用程序的入口点。//#include "stdafx.h"#include <iostream> #include <boost/thread/thread.hpp> #include <boost/thread/mutex.hpp> #include <boost/thread/condition.hpp> #include <boost/date_time/posix_time/posix_time.hpp> using namespace std;using namespace boost;boost::mutex test_mutex; boost::condition_variable test_condition; //#pragma comment(lib,"../../lib/x86/boost/libboost_thread-vc100-mt-gd-1_55.lib")//#pragma comment(lib,"..//..//lib//x86//boost//libboost_thread-vc100-mt-gd-1_55.lib")////../../lib/x86/boost/libboost_thread-vc100-mt-gd-1_55.lib;../../lib/x86/boost/libboost_date_time-vc100-mt-gd-1_55.lib;../../lib/x86/boost/libboost_system-vc100-mt-gd-1_55.lib;../../lib/x86/boost/libboost_chrono-vc100-mt-gd-1_55.libvoid test(){ for (;;) { boost::mutex::scoped_lock lock(test_mutex); if (test_condition.timed_wait(lock, get_system_time() + posix_time::seconds(3))) { cout << "成功接收到通知" << endl; //这里加个break就结束了 } else { cout << "没有等待到通知" << endl; } }}int _tmain(int argc, _TCHAR* argv[]){ boost::thread test_thread(test); for (;;) { ::system("PAUSE"); cout << "开始发送通知" << endl; test_condition.notify_one(); } return 0;}
0 0
- boost::condition_variable、boost::time_wait使用方法
- boost::condition_variable、boost::time_wait使用方法
- boost::condition_variable的使用
- boost条件变量(condition_variable…
- boost::time_wait的例子
- Boost 使用方法
- Boost 使用方法
- boost条件变量(condition_variable)wait操作传
- boost::condition_variable 设计c++ 生产者消费者队列
- boost::condition_variable 设计c++ 生产者消费者队列
- boost::condition_variable 设计c++ 生产者消费者队列
- boost::condition_variable 设计生产者消费者队列
- boost::condition_variable 设计c++ 生产者消费者队列
- boost中的condition_variable (条件变量)的使用
- boost综合使用<function,bind,thread,mutex,condition_variable,shared_ptr>
- boost.python使用方法
- boost::thread使用方法
- boost::bind的使用方法
- This function or variable may be unsafe. VS
- git远程操作常用命令
- Codeforces Round #334 (Div. 2) A. Uncowed Forces (水题)
- AsyncTask 异步任务
- Python基础02 基本数据类型
- boost::condition_variable、boost::time_wait使用方法
- 关于索引的B tree B-tree B+tree B*tree 详解结构图
- SPI、IIC、UART区别
- 高性能流媒体服务器-nebula之数据结构(6)--无节点内存分配的单、双链表
- 哎,学一半发现难以绕过著名数据分析模块
- java自增策略小陷阱
- 详解自主实现RecyclerView下拉刷新、上拉加载、Header、Footer以及swiperefreshlayout的部分讲解
- MD5加密函数签名校验+时间戳时间间隔校验
- *** No rule to make target