Boost logo

Boost Users :

Subject: [Boost-users] [coroutine] Resuming of coroutine from another thread
From: Jason Roehm (jasonr_at_[hidden])
Date: 2013-09-13 16:54:55


I'm thinking up a design for a task-processing system that uses
Boost.Asio and Boost.Coroutine. As part of that design, I would have a
pool of worker threads executing work items. During processing of a
particular work item, it's possible that the worker might need to wait
on some other operation (e.g. I/O) to complete. However, while it waits,
I'd like to put that thread to work doing something else useful from the
queue. I was thinking of using coroutines to provide the ability to
suspend the processing of one task, restarting it later when it is ready
to move forward again. In my hypothetical framework, the thread that
finishes the work might not be the same one that started it in the first
place.

I recently came across this Stack Overflow question:

http://stackoverflow.com/questions/8557067/thread-safe-coroutines-with-asio

which inquired as to the safety of creating a coroutine in one thread
and then resuming it in another. The answers there indicate that this is
not supported, and they link to Boost.Coroutine documentation that
explains the underlying problems and why it isn't supported. However,
that documentation was from the original Boost.Coroutine by Giovanni
Deretta (which I'm not sure was ever actually accepted into Boost). The
latest version by Oliver Kowalke indicates that it is a follow-up on
that library, but doesn't have any specific caveats in the documentation
regarding the interaction between threads and coroutines.

Does the contemporary Boost.Coroutine have the same limitation, or is it
safe to create a coroutine in one thread and then resume it in another?

Jason


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net