Skip to content

Instantly share code, notes, and snippets.

@boxdot
Last active August 22, 2016 19:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save boxdot/6b930f7ce248064f2bb51d5da39be27b to your computer and use it in GitHub Desktop.
Save boxdot/6b930f7ce248064f2bb51d5da39be27b to your computer and use it in GitHub Desktop.
#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