Releasing Execution Contexts [Crystal]
17 hours ago
- #multithreading
- #fiber-orchestration
- #execution-contexts
- Execution contexts in Crystal allow different models for fiber orchestration: concurrent (concurrency on one thread), parallel (concurrency and parallelism across cores), and isolated (a fiber owns a thread).
- The default execution context is parallel with parallelism of 1, avoiding breaking changes; it can be resized for true parallelism or kept concurrent as needed.
- Fibers can communicate across contexts using Channel and Sync types, though cross-context communication may be slower due to increased synchronization.
- Execution contexts solve issues from the preview MT model, such as fibers being stuck on busy threads, by allowing fibers to switch threads and schedulers to move threads on blocking syscalls.
- Breaking changes include fibers switching threads in parallel contexts, schedulers switching threads on blocking syscalls, and deprecation of the spawn(same_thread: true) argument.