Skip to content

Refactor: simplify Crystal::Scheduler#17091

Draft
ysbaddaden wants to merge 6 commits into
crystal-lang:masterfrom
ysbaddaden:refactor/simplify-crystal-scheduler
Draft

Refactor: simplify Crystal::Scheduler#17091
ysbaddaden wants to merge 6 commits into
crystal-lang:masterfrom
ysbaddaden:refactor/simplify-crystal-scheduler

Conversation

@ysbaddaden

@ysbaddaden ysbaddaden commented Jun 22, 2026

Copy link
Copy Markdown
Collaborator

A quick refactor to simplify Crystal::Scheduler for :without_mt. It allows safe fiber.enqueue from any thread, which will help to simplify a couple cases on Windows where IOCP doesn't quite fit (e.g. ReadConsoleW for reading from stdin and RegisterWaitSingleObject to wait for processes).

Follow up to #17001.

@ysbaddaden

This comment was marked as resolved.

There can also only be one event loop and stack pool. No need to
associate them to the scheduler, and no need to associate the scheduler
to the current thread (quite the opposite).
So we can enqueue fibers to the scheduler from other threads.
@ysbaddaden ysbaddaden force-pushed the refactor/simplify-crystal-scheduler branch from 8c1eaca to 7f12e6c Compare June 23, 2026 10:31
@ysbaddaden

Copy link
Copy Markdown
Collaborator Author

Allright, we used to not initialize the schedulers for interpreted code (sigh) and a nilable is always better than uninitialized (my bad).

Comment thread src/crystal/scheduler.cr Outdated
Comment thread src/crystal/scheduler.cr
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Jun 23, 2026
ysbaddaden added a commit to ysbaddaden/crystal that referenced this pull request Jun 25, 2026
Until crystal-lang#17091 a mere fiber enqueue will instantiate a scheduler (and
event loop) for the bare thread. It happens once, and the scheduler will
never run, but it's pointless.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Status: Review

Development

Successfully merging this pull request may close these issues.

2 participants