Boost C++ Libraries: Ticket #13570: asio_handler_invoke resume wrong thread in coroutine https://svn.boost.org/trac10/ticket/13570 <p> Environment:<br /> Windows 10, VS2015 Update3, Boost 1.65.1, Boost 1.67.0, x86/x64<br /> </p> <p> Coroutine should be suspended and resumed by the same thread, but in boost 1.67.0 it doesn't. I guess it's a bug introduced since boost 1.66. </p> <p> In Boost 1.65.0, correct behavior, output:<br /> thread : 37c0<br /> thread : 37c0<br /> hello<br /> </p> <p> In Boost 1.67.0, wrong behavior, output:<br /> thread : df4<br /> thread : 1844<br /> hello<br /> </p> <pre class="wiki">#include &lt;iostream&gt; #include &lt;boost/asio.hpp&gt; #include &lt;boost/asio/spawn.hpp&gt; #include &lt;boost/bind.hpp&gt; #include &lt;boost/thread.hpp&gt; std::string Test(boost::asio::io_service&amp; ios, boost::asio::yield_context yield) { boost::asio::io_service::work work(ios); #if BOOST_VERSION &gt;= 106600 boost::asio::async_completion&lt; boost::asio::yield_context, void(boost::system::error_code, std::string)&gt; init(BOOST_ASIO_MOVE_CAST(boost::asio::yield_context)(yield)); auto handler = init.completion_handler; #else boost::asio::detail::async_result_init&lt; boost::asio::yield_context, void(boost::system::error_code, std::string)&gt; init(BOOST_ASIO_MOVE_CAST(boost::asio::yield_context)(yield)); auto handler = init.handler; #endif boost::thread t([&amp;handler]() { boost::this_thread::sleep_for(boost::chrono::seconds(2)); boost::asio::detail::asio_handler_invoke( boost::bind&lt;void&gt;( handler, boost::system::error_code(), "hello"), &amp;handler); }); t.detach(); return init.result.get(); } int main(int argc, char* argv[]) { boost::asio::io_service ios; boost::asio::spawn(ios, [&amp;ios](boost::asio::yield_context yield) { boost::system::error_code ec; std::cout &lt;&lt; "thread : " &lt;&lt; boost::this_thread::get_id() &lt;&lt; std::endl; std::string msg = Test(ios, yield[ec]); std::cout &lt;&lt; "thread : " &lt;&lt; boost::this_thread::get_id() &lt;&lt; std::endl; std::cout &lt;&lt; msg &lt;&lt; std::endl; }); ios.run(); std::string tmp; std::cin &gt;&gt; tmp; return 0; } </pre> en-us Boost C++ Libraries /htdocs/site/boost.png https://svn.boost.org/trac10/ticket/13570 Trac 1.4.3