Skip to content

RFC 2: Add Fiber::ExecutionContext::SingleThreaded scheduler #15511

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

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Feb 24, 2025

Introduces the first EC scheduler that runs in a single thread.

Uses the same queues (Runnables, GlobalQueue) as the multithreaded scheduler that will come next. The Runnables local queue could be simplified (no parallel accesses, hence no need for atomics) at the expense of duplicating the implementation.

The scheduler doesn't need to actively park the thread; the event loops always block (when told to) even when there are no events, which acts as parking the thread.

NOTE: we can start running the specs in this context (they pass locally), though there might be some issues until we replace rogue Thread instances with bubble wrapped ExecutionContext::Isolated (coming in another PR). If you wanna try:

$ make std_spec FLAGS="-Dpreview_mt -Dexecution_context"
$ make compiler_spec FLAGS="-Dpreview_mt -Dexecution_context"

Refs #15342

Introduces the first EC scheduler that runs in a single thread.

Uses the same queues (Runnables, GlobalQueue) as the multi-threaded
scheduler that will come next. The Runnables local queue could be
simplified (no parallel accesses, hence no need for atomics) at the
expense of duplicating the implementation.

The scheduler doesn't need to actively park the thread; the event loops
always block (when told to) even when there are no events, which acts as
parking the thread.
@ysbaddaden ysbaddaden changed the title Add ExecutionContext::SingleThreaded scheduler Add Fiber::ExecutionContext::SingleThreaded scheduler Feb 24, 2025
Co-authored-by: Johannes Müller <[email protected]>
@ysbaddaden ysbaddaden changed the title Add Fiber::ExecutionContext::SingleThreaded scheduler RFC 2: Add Fiber::ExecutionContext::SingleThreaded scheduler Mar 3, 2025
@straight-shoota straight-shoota added this to the 1.16.0 milestone Mar 14, 2025
@straight-shoota straight-shoota changed the title RFC 2: Add Fiber::ExecutionContext::SingleThreaded scheduler RFC 2: Add Fiber::ExecutionContext::SingleThreaded scheduler Mar 14, 2025
@straight-shoota straight-shoota merged commit 09b4fbb into crystal-lang:master Mar 17, 2025
32 checks passed
@github-project-automation github-project-automation bot moved this from Review to Done in Multi-threading Mar 17, 2025
@ysbaddaden ysbaddaden deleted the feature/execution-context-single-threaded branch March 17, 2025 08:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Done
Development

Successfully merging this pull request may close these issues.

2 participants