Skip to content
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

Explicit Crystal.once_init method #15371

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ysbaddaden
Copy link
Contributor

@ysbaddaden ysbaddaden commented Jan 24, 2025

Adds Crystal.once_init that allows to remove the Crystal.once_mutex= setter.

It also removes the need for the __crystal_once_init fun that won't be defined anymore —it's only kept for the legacy implementation. This is one less compiler dependency on runtime.

Follow up to #15369

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 -> ...
Prefer a def explictly called by `Crystal.init_runtime` over the
implicit `__crystal_once_init` fun injected by the compiler.

The fun is no longer defined for new compiler builds, however it's still
defined to support older compiler releases.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant