diff --git a/examples/asio/autoecho.cpp b/examples/asio/autoecho.cpp index 2f46d97c..8cf3f7de 100644 --- a/examples/asio/autoecho.cpp +++ b/examples/asio/autoecho.cpp @@ -233,32 +233,38 @@ int main( int argc, char* argv[]) { try { boost::asio::io_service io_svc; boost::fibers::use_scheduling_algorithm< boost::fibers::asio::round_robin >( io_svc); + print( "Thread ", thread_names.lookup(), ": started"); // server boost::fibers::fiber f( server, boost::ref( io_svc) ); // run io_service in two threads std::thread t([&io_svc](){ - boost::fibers::use_scheduling_algorithm< boost::fibers::asio::round_robin >( io_svc); - print( "Thread ", thread_names.lookup(), ": started"); - // client - const unsigned iterations = 20; - const unsigned clients = 3; - boost::fibers::barrier barrier(clients); - for (unsigned c = 0; c < clients; ++c) { - boost::fibers::fiber( - client, boost::ref( io_svc), boost::ref( barrier), - iterations ).detach(); - } - io_svc.run(); - print( "Thread ", thread_names.lookup(), ": stopping"); + try { + boost::fibers::use_scheduling_algorithm< boost::fibers::asio::round_robin >( io_svc); + print( "Thread ", thread_names.lookup(), ": started"); + // client + const unsigned iterations = 2; + const unsigned clients = 3; + boost::fibers::barrier barrier(clients); + for (unsigned c = 0; c < clients; ++c) { + boost::fibers::fiber( + client, boost::ref( io_svc), boost::ref( barrier), + iterations ).detach(); + } + boost::fibers::asio::run_svc( io_svc); + print( "Thread ", thread_names.lookup(), ": stopping"); + } catch ( boost::fibers::fiber_interrupted const&) { + print( tag(), " : interrupted"); + } catch ( std::exception const& ex) { + print( tag(), " : catched exception : ", ex.what()); + } }); - io_svc.run(); print( tag(), " : back from io_service::run(), waiting for thread"); t.join(); print( tag(), " : back from thread.join(), waiting for server fiber"); f.interrupt(); f.join(); - print( "done."); + print( "Thread ", thread_names.lookup(), ": stopping"); return EXIT_SUCCESS; } catch ( std::exception const& e) { print("Exception: ", e.what(), "\n"); diff --git a/examples/asio/echo.cpp b/examples/asio/echo.cpp index 9224b447..f11ee9f8 100644 --- a/examples/asio/echo.cpp +++ b/examples/asio/echo.cpp @@ -146,9 +146,9 @@ int main( int argc, char* argv[]) { // run io_service in two threads std::thread t([&io_svc](){ boost::fibers::use_scheduling_algorithm< boost::fibers::asio::round_robin >( io_svc); - io_svc.run(); + boost::fibers::asio::run_svc( io_svc); }); - io_svc.run(); + boost::fibers::asio::run_svc( io_svc); t.join(); std::cout << "done." << std::endl; return EXIT_SUCCESS; diff --git a/examples/asio/ps/server.cpp b/examples/asio/ps/server.cpp index 5bd06cee..bcbdab80 100644 --- a/examples/asio/ps/server.cpp +++ b/examples/asio/ps/server.cpp @@ -377,7 +377,7 @@ int main( int argc, char* argv[]) { boost::fibers::fiber( accept_subscriber, boost::ref( io_service), 9998, boost::ref( reg) ).detach(); // dispatch - io_service.run(); + boost::fibers::asio::run_svc( io_service); return EXIT_SUCCESS; } catch ( std::exception const& e) { std::cerr << "Exception: " << e.what() << "\n";