diff --git a/CHANGELOG.md b/CHANGELOG.md index f0e9fb2d..359db166 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ Version 168: * Use executor_work_guard in composed operations * Revert verb.ipp change which caused spurious warnings +* Fix race in advanced server examples -------------------------------------------------------------------------------- diff --git a/example/advanced/server-flex/advanced_server_flex.cpp b/example/advanced/server-flex/advanced_server_flex.cpp index b1f4ef71..c9e56a24 100644 --- a/example/advanced/server-flex/advanced_server_flex.cpp +++ b/example/advanced/server-flex/advanced_server_flex.cpp @@ -924,6 +924,15 @@ public: void run() { + // Make sure we run on the strand + if(! strand_.running_in_this_thread()) + return boost::asio::post( + boost::asio::bind_executor( + strand_, + std::bind( + &plain_http_session::run, + shared_from_this()))); + // Run the timer. The timer is operated // continuously, this simplifies the code. on_timer({}); @@ -996,6 +1005,15 @@ public: void run() { + // Make sure we run on the strand + if(! strand_.running_in_this_thread()) + return boost::asio::post( + boost::asio::bind_executor( + strand_, + std::bind( + &ssl_http_session::run, + shared_from_this()))); + // Run the timer. The timer is operated // continuously, this simplifies the code. on_timer({}); diff --git a/example/advanced/server/advanced_server.cpp b/example/advanced/server/advanced_server.cpp index d814cb48..7b9980f8 100644 --- a/example/advanced/server/advanced_server.cpp +++ b/example/advanced/server/advanced_server.cpp @@ -578,6 +578,15 @@ public: void run() { + // Make sure we run on the strand + if(! strand_.running_in_this_thread()) + return boost::asio::post( + boost::asio::bind_executor( + strand_, + std::bind( + &http_session::run, + shared_from_this()))); + // Run the timer. The timer is operated // continuously, this simplifies the code. on_timer({});