Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Explicit context switch of fibers #323

Open
SerenGTI opened this issue Jul 26, 2024 · 0 comments
Open

Explicit context switch of fibers #323

SerenGTI opened this issue Jul 26, 2024 · 0 comments

Comments

@SerenGTI
Copy link

Hi there,
I am currently researching the behavior of non-blocking code such as boost::fiber under different scheduling mechanisms. One such mechanism is the symmetric transfer, wherein one fiber is suspended and another fiber is immediately resumed with no caller/callee relationship between the two.

Hence, I would like to explicitly resume a previously suspended fiber in the current thread, bypassing the scheduler. Assume I have a list of suspended fibers, represented by their contexts, for example as

std::deque<context*> suspended_contexts;

Now, in a running fiber, let's call it F, I would like to be able to yield F and then resume suspended_contexts.front() without passing control to any other fibers that may be in the scheduler's ready queue. However, I seem to be unable to get context->attach(), context->resume() or any other method used throughout the codebase to work.

I know that the scheduler realizes a context switch between fibers through

// resume another context
algo_->pick_next()->resume();

which essentially does

context::active()->attach(next_fiber_context);
next_fiber_context->resume();

however, when I use next_fiber_context = suspended_contexts.front(), my code deadlocks on the call to resume().

Am I missing something crucial about the fiber context switch?
Could you direct me to a more detailed documentation of a context switch as it is used in the library?

Moreover, is there a way to pass the suspended fiber F to the scheduler so that another thread may execute it in the meantime? A fiber must be explicitly enqueued into the scheduler's ready queue by calling awakened(ctx). Is it safe to do so with ctx = context::active()?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant