Opened 9 years ago

Closed 8 years ago

#9442 closed Bugs (fixed)

boost::asio::spawn does nothing when coroutines v2 are enabled

Reported by: drigh@… 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 drigh@…, 9 years ago

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;
 #endif

not entirely sure it'll work, but it definitely seems to

comment:2 by anonymous, 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 chris_kohlhoff, 8 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.