Explicit init of Thread and Fiber class variables#15369
Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom Jan 25, 2025
Merged
Conversation
Member
|
Can we split this into two PRs? I understand the changes are largely independent of each other. |
f2b1909 to
a1cbb2f
Compare
Replaces the implicit initialization of Thread and Fiber class variables with an explicit initializer since both should be initialized before `__crystal_once_init` is called. This is working for now because the `class_[getter|property]` macros in Thread and Fiber don't protect against either recursion nor parallel initializations, but we plan to protect them (using Mutex) which would immediately break with an infinite recursion: Mutex#lock -> Fiber#current -> Thread#current -> Mutex#lock -> ...
a1cbb2f to
39d88fa
Compare
straight-shoota
approved these changes
Jan 24, 2025
1 task
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.
Adds
Thread.init,Fiber.initthat explicitly initialize the class variables defined onThreadandFiber.In order to implement #14905 we'll need the ability to access
Fiber.currentwhich depends onThread.currentbut if these accessors use the class getter/property macros then we'll enter an infinite recursion.AddsCrystal.once_initto allow to remove theCrystal.once_mutex=setter. It also removes the need for the__crystal_once_initfun which won't be defined anymore —it's only kept for the legacy implementation.Those initializers are now explicitly called from a new
Crystal.init_runtimemethod called byCrystal.main, but also by the interpreter that doesn't callCrystal.main—not currently needed, but it will be to reuse crystal/once to implement #14905.