Skip to content

Instantly share code, notes, and snippets.

@inetic
Created November 7, 2014 12:29
Show Gist options
  • Save inetic/f32be2e32e9572af7828 to your computer and use it in GitHub Desktop.
Save inetic/f32be2e32e9572af7828 to your computer and use it in GitHub Desktop.
#include <iostream>
#include <thread>
#include <future>
#include <boost/asio.hpp>
using namespace std;
namespace asio = boost::asio;
int main() {
asio::io_service ios;
auto work = make_shared<asio::io_service::work>(ios);
thread t([&]() { ios.run(); });
for (int i = 0; i < 1000; ++i)
{
promise<bool> setter;
future<bool> getter = setter.get_future();
ios.post([&]() { setter.set_value(true); });
getter.wait();
}
work.reset();
t.join();
cout << "done\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment