Skip to content

Instantly share code, notes, and snippets.

@snaewe
Last active October 11, 2015 01:38
Show Gist options
  • Save snaewe/3782446 to your computer and use it in GitHub Desktop.
Save snaewe/3782446 to your computer and use it in GitHub Desktop.
Run boost::asio::io_service::run in a thread
// -*- c++ -*-
// compile with: "g++ -D_WIN32_WINNT=0x501 run_iosvc_in_thread.cpp -lboost_thread -lboost_system -lwsock32 -o run_iosvc_in_thread"
#include <boost/asio.hpp>
#include <boost/thread.hpp>
#include <boost/bind.hpp>
#include <boost/scoped_ptr.hpp>
int main()
{
boost::scoped_ptr<boost::asio::io_service> m_ioServicePtr(new boost::asio::io_service);
boost::scoped_ptr<boost::thread> m_logThread(new boost::thread( boost::bind( &boost::asio::io_service::run, m_ioServicePtr.get() )));
m_logThread->join();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment