Boost logo

Boost Users :

From: chris-boostusers_at_[hidden]
Date: 2022-08-31 22:21:17


On 8/28/22 4:06 PM, Gavin Lambert via Boost-users wrote:
> Scheduling coroutines is in Boost.Fiber's wheelhouse.  I don't think it
> provides a priority-based scheduler out of the box, but it does discuss
> it as a customisation point at

Gavin,

Thank you. I had never heard of a "fiber" before but they are
brilliant. Coroutines without coroutines!

I ended up writing my own "algorithm" based on your suggestions. I had
to overcome these issues:

1. When using multiple threads (to run fibers in parallel), the
boost-provided algorithms busy-wait when there is no work to do. They
have an option to suspend but they don't wake up to "steal" or "share"
fibers from other threads. So my algorithm has a mechanism to wake up
idle threads when excess work appears on a non-idle thread.

2. I added "priority" so a high priority can preempt a lower priority fiber

3. boost::fibers::yield() needed a modification to handle priorities. If
the highest priority fiber calls yield(), and there are only lower
priority fibers, control will be yielded to a lower priority fiber --
without input from the "algorithm". I would have preferred if the
custom algorithm could have vetoed the context switch. But instead I
wrote my own yield that consulted with the algo. This modification
would have been easier if boost::fibers::scheduler::get_algo() were
provided.

Anyhow, thanks again. This is a wonderful library.

Chris


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