boost:thread2
来源:互联网 发布:制作动漫软件下载 编辑:程序博客网 时间:2024/06/15 02:32
#include <iostream>
#include <fstream>
#include <boost/thread/thread.hpp>
#include <boost/thread/mutex.hpp>
#include <boost/thread/condition.hpp>
void wait(int seconds)
{
boost::this_thread::sleep(boost::posix_time::seconds(seconds));
}
boost::mutex mutex;
boost::condition_variable_any cond;
void test_wait()
{
std::fstream outFile("D:/time.txt",std::ios_base::out);
while(true)
{
boost::mutex::scoped_lock lock(mutex);
cond.wait(mutex);
std::cout<<boost::this_thread::get_id()<<" 收到notify!\n";
outFile<<boost::this_thread::get_id()<<" 收到notify!\n";
}
outFile.close();
}
void main()
{
boost::thread t1(test_wait);
boost::thread t2(test_wait);
boost::thread t3(test_wait);
boost::thread t4(test_wait);
int cnt = 0;
while (true)
{
wait(1);cnt++;
cond.notify_one();
if ( cnt == 50 )
break;
}
system("pause");
}
output
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
00448138 收到notify!
004480A8 收到notify!
004480A8 收到notify!
- boost:thread2
- Thread2
- Thread2
- Thread2
- Thread2
- Thread2(C#)
- Thread2 关键字
- Thread thread2 = new Thread()
- Thread thread2 = new Thread()
- Android中的MessageQueue,Handler,Looper和Thread2
- java 线程thread2(线程同步 synchronized)
- Boost
- boost
- boost
- Boost
- boost
- boost
- Boost
- Android代码编写规范
- svn迁移
- E: 无法获得锁 /var/lib/dpkg/lock - open (11: 资源暂时不可用)
- logic pro X 扫不出Waves All Plugins Bundle v9r11
- base的笔记
- boost:thread2
- jQuery file upload 中服务端需要提供的json格式
- 新随笔(三)什么时候使用按钮,什么时候使用文字链接
- BAT命令详解
- mac x 获取root 权限
- 将屏幕保存为图片 将当前MFC程序保存为图片 c++ vc
- R12 编译 FORM
- 如何做DIV模态窗口
- Fedora 启动顺序