jbaldwin / libcoro

C++20 coroutine library

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Any chance to easily capture the "execution/synchronization" context?

dok-net opened this issue · comments

.NET / C# by default captures the context and procedes to continuations from awaited async tasks in that captured context, i.e. the thread that called the await foo(); statement in the first place. There exists ConfigureAwait(false) to change this, that is, the continuation gets called by the context, the thread, that is running the awaited task at the time it is returning.

libcoro is like always ConfigureAwait(false). And there is no facility to capture the prior context.

Yeah it's definitely possible. coro::thread_pool needs to to have individual queues for resuming on that specific thread, it would probably have higher priority than the current global queue. The coro::task then needs to keep a thread index and queue itself onto that threads queue instead of the global queue.

I was thinking in a more generic direction, to use even when the THREADING option is not set and we are implementing our own schedulers (on embedded targets).

I don't think I'll implement this feature into libcoro right now, it will introduce a lot more complexity in scheduling tasks and how local vs global queues interact.