Last active
August 22, 2016 19:19
-
-
Save boxdot/6b930f7ce248064f2bb51d5da39be27b 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 <boost/asio.hpp> | |
#include <thread> | |
#include <iostream> | |
int main(int argc, char const *argv[]) | |
{ | |
boost::asio::io_service service; | |
boost::asio::io_service::work work(service); | |
std::thread thread([&service](){ service.run(); }); | |
int runs = 0; | |
for (int i = 0; i < 10000; ++i) { | |
service.post([&runs](){ | |
runs++; | |
}); | |
} | |
// the output here is always < 9999 and is non-deterministic | |
std::cout << runs << std::endl; | |
service.stop(); | |
thread.join(); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment