Created
November 7, 2014 12:29
-
-
Save inetic/f32be2e32e9572af7828 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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