Last active
July 27, 2021 14:04
-
-
Save vinipsmaker/2ec8027f64f4bec4e2bb7fbc70d27fa8 to your computer and use it in GitHub Desktop.
This file contains hidden or 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 <optional> | |
#include <iostream> | |
#include <thread> | |
#include <mutex> | |
#include <boost/asio/io_context_strand.hpp> | |
#include <boost/asio/bind_executor.hpp> | |
#include <boost/asio/signal_set.hpp> | |
#include <boost/asio/post.hpp> | |
namespace asio = boost::asio; | |
int main() | |
{ | |
asio::io_context ctx; | |
asio::io_context::strand strand1{ctx}; | |
asio::io_context::strand strand2{ctx}; | |
std::optional<asio::signal_set> sig; | |
std::mutex sig_mtx; | |
asio::post( | |
strand1, | |
asio::bind_executor(strand1, [&]() { | |
{ | |
std::lock_guard<std::mutex> guard(sig_mtx); | |
sig.emplace(ctx, SIGUSR1); | |
} | |
sig->async_wait(asio::bind_executor( | |
strand1, | |
[&](boost::system::error_code ec, int /*signo*/) { | |
std::cerr << "test\n"; | |
sig.reset(); | |
} | |
)); | |
}) | |
); | |
std::optional<asio::signal_set> sig2; | |
asio::post( | |
strand2, | |
asio::bind_executor(strand2, [&]() { | |
{ | |
std::lock_guard<std::mutex> guard(sig_mtx); | |
sig2.emplace(ctx, SIGUSR1); | |
} | |
sig2->async_wait(asio::bind_executor( | |
strand2, | |
[&](boost::system::error_code ec, int /*signo*/) { | |
std::cerr << "test\n"; | |
sig2.reset(); | |
} | |
)); | |
}) | |
); | |
std::thread t{[&]() { ctx.run(); }}; | |
ctx.run(); | |
t.join(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment