Boost-IO-多线程 (转)

#include <boostasio.hpp>
#include <iostream>
#include <boost	hread.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();
	
}

  

原文地址:https://www.cnblogs.com/AXIA-zy/p/4450402.html