Opened 9 years ago
Closed 8 years ago
#9442 closed Bugs (fixed)
boost::asio::spawn does nothing when coroutines v2 are enabled
| Reported by: | Owned by: | chris_kohlhoff | |
|---|---|---|---|
| Milestone: | To Be Determined | Component: | asio |
| Version: | Boost 1.55.0 | Severity: | Problem |
| Keywords: | Cc: |
Description
Following code works as expected (i.e. prints 'works'). However, it prints nothing if you uncomment lines that enable (or try to enable) use of coroutines v2 in spawn.
#include <iostream>
#include <functional>
//#define BOOST_COROUTINES_UNIDIRECT
//#define BOOST_COROUTINES_V2
#include <boost/asio.hpp>
#include <boost/asio/spawn.hpp>
void foo(boost::asio::yield_context ctx)
{
std::cout << "works!" << std::endl;
}
int main()
{
boost::asio::io_service srv;
boost::asio::spawn(srv, std::bind(foo, std::placeholders::_1));
srv.run();
}
I am not sure if asio is intentionally not using new coroutines interface by default, but this seems pretty important thing going forward.
Change History (3)
comment:1 by , 9 years ago
comment:2 by , 9 years ago
It is typo here in asio code:
#elif defined(BOOST_COROUTINES_UNIDRECT) ...
should be
#elif defined(BOOST_COROUTINES_UNIDIRECT) ...
comment:3 by , 8 years ago
| Resolution: | → fixed |
|---|---|
| Status: | new → closed |
Fixed on 'develop' in 85640f548a6e0934fc3103ccf8643c5c6eaed960.
Merged to 'master' in 4e1e7d731fcc5c0104567856de476f7ce8806d72.

this is my fix on top of boost 1.55.0:
diff --git a/boost/asio/spawn.hpp b/boost/asio/spawn.hpp index 0d7ee77..232e2e0 100644 --- a/boost/asio/spawn.hpp +++ b/boost/asio/spawn.hpp @@ -54,12 +54,12 @@ public: * When using Boost.Coroutine v1, this type is: * @code typename coroutine<void()> @endcode * When using Boost.Coroutine v2 (unidirectional coroutines), this type is: - * @code push_coroutine<void> @endcode + * @code pull_coroutine<void> @endcode */ #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined callee_type; #elif defined(BOOST_COROUTINES_UNIDRECT) || defined(BOOST_COROUTINES_V2) - typedef boost::coroutines::push_coroutine<void> callee_type; + typedef boost::coroutines::pull_coroutine<void> callee_type; #else typedef boost::coroutines::coroutine<void()> callee_type; #endif @@ -69,12 +69,12 @@ public: * When using Boost.Coroutine v1, this type is: * @code typename coroutine<void()>::caller_type @endcode * When using Boost.Coroutine v2 (unidirectional coroutines), this type is: - * @code pull_coroutine<void> @endcode + * @code push_coroutine<void> @endcode */ #if defined(GENERATING_DOCUMENTATION) typedef implementation_defined caller_type; #elif defined(BOOST_COROUTINES_UNIDRECT) || defined(BOOST_COROUTINES_V2) - typedef boost::coroutines::pull_coroutine<void> caller_type; + typedef boost::coroutines::push_coroutine<void> caller_type; #else typedef boost::coroutines::coroutine<void()>::caller_type caller_type; #endifnot entirely sure it'll work, but it definitely seems to