You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am using the Boost.Fiber <-> Boost.Asio coupling via the boost::fibers::asio::round_robin scheduler, and I am trying to relaunch an asio io_service, that has previously been stopped.
The problem is, that the scheduler (or fiber) hangs after the second execution of the .run() method.
In the code example below, the "this line is never reached\n" string is never printed.
#include<iostream>
#include<boost/asio/io_context.hpp>
#include"round_robin.hpp"
#include<boost/fiber/all.hpp>using io_context_ptr = std::shared_ptr<boost::asio::io_service>;
voidstart(io_context_ptr io_ctx)
{
boost::asio::system_timer t(*io_ctx);
t.expires_after(std::chrono::seconds(1));
t.async_wait(boost::fibers::asio::yield);
io_ctx->stop();
}
intmain()
{
io_context_ptr io_ctx = std::make_shared<boost::asio::io_service>();
boost::fibers::use_scheduling_algorithm<boost::fibers::asio::round_robin>(io_ctx);
auto f = boost::fibers::fiber(start, io_ctx);
io_ctx->run();
f.join();
std::cout << "foo\n";
io_ctx->restart();
auto f2 = boost::fibers::fiber(start, io_ctx);
std::cout << "bar\n";
io_ctx->run();
std::cout << "this line is never reached\n";
f2.join();
}
The text was updated successfully, but these errors were encountered:
niekbouman
changed the title
[boost asio interactionRestarting
[boost asio interaction] Restarting an io_service
Mar 4, 2020
if I remember well you have to reset your service before restart it (there is a restart function btw). I suggest to carefully read the documentation, sometimes functions names are misinterpreted or require a context not so evident.
Hi,
I am using the Boost.Fiber <-> Boost.Asio coupling via the
boost::fibers::asio::round_robin
scheduler, and I am trying to relaunch an asioio_service
, that has previously been stopped.The problem is, that the scheduler (or fiber) hangs after the second execution of the
.run()
method.In the code example below, the "this line is never reached\n" string is never printed.
The text was updated successfully, but these errors were encountered: