Boost-IO-多线程 (转)

#include <boost\asio.hpp>
#include <iostream>
#include <boost\thread.hpp>

using namespace std;
void handler(const boost::system::error_code &ec)
{
	cout << "5s" << endl;
}


void handler2(const boost::system::error_code &ec)
{
	cout << "5s" << endl;
}

boost::asio::io_service io_service;
boost::asio::io_service io_service2;
void run()
{
	io_service.run();
}
void run2()
{
	io_service2.run();
}
int main()
{
 
	boost::asio::deadline_timer timer(io_service, boost::posix_time::seconds(5));
	timer.async_wait(handler);
	boost::asio::deadline_timer timer2(io_service2, boost::posix_time::seconds(10));
	timer2.async_wait(handler2);
	 
	boost::thread thread1(run);
	boost::thread thread2(run2);
	thread1.join();
	thread2.join();
	
}

  

posted @ 2015-04-23 14:14  AXIA_zy  阅读(198)  评论(0编辑  收藏  举报