How to clone Boost ASIO coroutine on fork?

Looking at the Boost ASIO http server example with coroutines I am wondering if the used cloning method is safe:

    // We "fork" by cloning a new server coroutine to handle the connection.
    // After forking we have a parent coroutine and a child coroutine. Both
    // parent and child continue execution at the following line. They can
    // be distinguished using the functions coroutine::is_parent() and
    // coroutine::is_child().
    fork server(*this)();

With that line a server object is copy constructed from the current object.

But isn't there the possibility that following happens:

  • the cloned child coroutine issues a yield
  • thus, the child's coroutine body is left
  • thus, the child's operator()() method is left
  • the parent destructs the child object
  • the parent starts a new iteration and yields
  • an async-method called by the child finishes
  • thus, the now (destructed) child coroutine is reentered
  • If it is safe, why?

    链接地址: http://www.djcxy.com/p/53166.html

    上一篇: 了解协程的执行

    下一篇: 如何在叉上克隆Boost ASIO协程?