Yielding or Rescheduling#

Yielding to Higher Priority Tasks#

constexpr aw_yield tmc::yield()#

Returns an awaitable that suspends this task and resubmits it back to its current executor, so that a higher priority task can run. Note that this can only be used to yield to a higher priority task; it cannot be used to enforce fair scheduling among tasks of the same priority level. If you need to do that, use tmc::reschedule() instead.

inline bool tmc::yield_requested()#

Returns true if a higher priority task is requesting to run on this thread.

constexpr aw_yield_if_requested tmc::yield_if_requested()#

Returns an awaitable that suspends this task only if a higher priority task is requesting to run on this thread.

co_await yield_if_requested();

is equivalent to

if (yield_requested()) { co_await yield();}

template<ptrdiff_t N>
inline aw_yield_counter<N> tmc::check_yield_counter()#

Returns an awaitable that, every N calls to co_await, checks yield_requested() and yields if that returns true. The counterpart function check_yield_counter_dynamic() allows passing N as a runtime parameter.

inline aw_yield_counter_dynamic tmc::check_yield_counter_dynamic(size_t N)#

Returns an awaitable that, every N calls to co_await, checks yield_requested() and yields if that returns true. The counterpart function check_yield_counter() allows setting N as a template parameter.

Rescheduling Tasks for Fairness#

constexpr aw_reschedule tmc::reschedule()#

Returns an awaitable that suspends this task and resubmits it back to its current executor using the FIFO inbox. This can be used to enforce fair scheduling among tasks of the same priority level.