-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refactor: add fiber safety to crystal/once
Removes the global mutex that prevents concurrent initializers to run, while still being able to detect reentrancy, by keeping a list of pending operations, protected by a global lock that doesn't block other initializers from running. Using a linked-list of stack allocated operations may sound inefficient compared to a `Hash` but there should usually not be many concurrent or parallel lazy initialization that following a few pointers will matter much in practice. This isn't very important for the eager initialization of class vars and constants that happen sequentially at the start of the program and before we even start threads, but we plan to reuse the feature to protect lazy initialization of class variables (i.e. the `class_getter` and `class_property` macros) when it would matter more. Introduces the `Crystal::Once` namespace. The initialization entry is now `Crystal::Once.init` instead of `Crystal.once_init`. Co-authored-by: David Keller <[email protected]>
- Loading branch information
1 parent
5fda40a
commit 3fba3df
Showing
2 changed files
with
131 additions
and
64 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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