RFC 2: Skeleton for ExecutionContext #15350
Merged
straight-shoota merged 16 commits intocrystal-lang:masterfrom Feb 22, 2025
Merged
RFC 2: Skeleton for ExecutionContext #15350straight-shoota merged 16 commits intocrystal-lang:masterfrom
straight-shoota merged 16 commits intocrystal-lang:masterfrom
Conversation
- Add the `ExecutionContext` module; - Add the `ExecutionContext::Scheduler` module; - Add the `execution_context` compile-time flag. When the `execution_context` flag is set: - Don't load `Crystal::Scheduler`; - Plug `ExecutionContext` instead of `Crystal::Scheduler` in `spawn`, `Fiber`, ... This is only the skeleton: there are no implementations (yet). Trying to compile anything with `-Dexecution_context` will obviously fail for the time being.
The current ST and MT schedulers use a distinct pool per thread, which means we only need the thread safety for execution contexts that will share a single pool for a whole context.
The point is to avoid parallel enqueues while running the event loop, so we get better control to where and how the runnable fibers are enqueued; for example all at once instead of one by one (may not be as effective as it sounds). More importantly for Execution Contexts: it avoids parallel enqueues while the eventloop is running which sometimes leads to confusing behavior; for example when deciding to wake up a scheduler/thread we musn't interryupt the event loop (obviously). This is working correctly for the Polling (Epoll, Kqueue) and IOCP event loop implementations. I'm less confident with the libevent one where the external library executes arbitrary callbacks.
Co-authored-by: Johannes Müller <straightshoota@gmail.com>
We need this because we don't load crystal/scheduler anymore when execution contexts are enabled.
straight-shoota
approved these changes
Jan 31, 2025
straight-shoota
approved these changes
Feb 3, 2025
Collaborator
Author
Collaborator
Author
|
Merged with master to bring in #15409 + solved conflicts. |
Collaborator
Author
|
I solved more conflicts. Now I can run my branch with the ST and MT schedulers using #15345 and this branch 👍 |
ysbaddaden
added a commit
to ysbaddaden/crystal
that referenced
this pull request
Feb 11, 2025
Collaborator
Author
|
As far as I can tell: there's nothing left to do here. Just waiting for a (final) review :) |
bcardiff
reviewed
Feb 20, 2025
straight-shoota
approved these changes
Feb 21, 2025
kojix2
pushed a commit
to kojix2/crystal
that referenced
this pull request
Feb 23, 2025
Integrates the skeleton as per crystal-lang/rfcs#2 - Add the `ExecutionContext` module; - Add the `ExecutionContext::Scheduler` module; - Add the `execution_context` compile-time flag. When the `execution_context` flag is set: - Don't load `Crystal::Scheduler`; - Plug `ExecutionContext` instead of `Crystal::Scheduler` in `spawn`, `Fiber`, ... This is only the skeleton: there are no implementations (yet). Trying to compile anything with `-Dexecution_context` will fail until the ST and/or MT context are implemented. Co-authored-by: Johannes Müller <straightshoota@gmail.com>
ysbaddaden
added a commit
to crystal-lang/rfcs
that referenced
this pull request
Feb 25, 2025
ysbaddaden
added a commit
to ysbaddaden/crystal
that referenced
this pull request
Mar 24, 2025
…tal-lang#15350] It's pointless because we always add the default context anyway. Let's make the initialization explicit.
ysbaddaden
added a commit
to ysbaddaden/crystal
that referenced
this pull request
Mar 24, 2025
1 task
straight-shoota
added a commit
to crystal-lang/crystal-book
that referenced
this pull request
Nov 5, 2025
Introduced in crystal-lang/crystal#15350
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Integrates the skeleton as per RFC #0002.
ExecutionContextmodule;ExecutionContext::Schedulermodule;execution_contextcompile-time flag.When the
execution_contextflag is set:Crystal::Scheduler;ExecutionContextinstead ofCrystal::Schedulerinspawn,Fiber, ...This is only the skeleton: there are no implementations (yet). Trying to compile anything with
-Dexecution_contextwill obviously fail until the follow up pull requests implementing at least the ST and/or MT context are merged.TODO:
Fiber.newafter InitializeFiberwith an explicit stack #15409 is merged;havenot needed: this is already done case inFiber::ExecutionContext#spawnto useself.stack_poolwhen creating the fiber.Fiber.new(with special case when interpreted);Fiber::Queuehas been renamedFiber::Listin Add fiber queues for execution context schedulers #15345Thread#dead_fiber_stack?(Void*vsFiber::Stack)refs #15342
depends on #15345