Skip to content

Instantly share code, notes, and snippets.

@vinniefalco
Created December 3, 2018 22:54
Show Gist options
  • Save vinniefalco/c723b10eccefa74bc179df688a7fbcc8 to your computer and use it in GitHub Desktop.
Save vinniefalco/c723b10eccefa74bc179df688a7fbcc8 to your computer and use it in GitHub Desktop.
// Capture SIGINT and SIGTERM to perform a clean shutdown
net::signal_set signals(ioc, SIGINT, SIGTERM);
signals.async_wait(
[&](beast::error_code const&, int)
{
// Stop the `io_context`. This will cause `run()`
// to return immediately, eventually destroying the
// `io_context` and all of the sockets in it.
ioc.stop();
});
// Run the I/O service on the requested number of threads
std::vector<std::thread> v;
v.reserve(threads - 1);
for(auto i = threads - 1; i > 0; --i)
v.emplace_back(
[&ioc]
{
ioc.run();
});
ioc.run();
// (If we get here, it means we got a SIGINT or SIGTERM)
// Block until all the threads exit
for(auto& t : v)
t.join();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment