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

Fix: Crystal::RWLock should be a struct #14345

Merged

Conversation

ysbaddaden
Copy link
Contributor

The Crystal::RWLock type is used to protect the GC against fiber context switches, to avoid the GC interrupting a thread while it is switching to another fiber, or starting a collection while a thread was preempted by the kernel while it was switching to another fiber.

Problem is: Crystal::RWLock is a class, and as such depends on the GC to be allocated, and... we end up in an infinite loop: GC <-> Crystal::RWLock.

The weirdest part is that it's working, and I have no idea how.

The Crystal::RWLock type is used to protect the GC against fiber context
switches, to avoid the GC interrupting a thread while it is switching
contexts, or starting a collection while a thread was preempted by the
kernel while it was switching the fiber context.

Problem is: Crystal::RWLock is a class, and thus depends on the GC to
be allocated, and we end up in an infinite loop: GC depends on
Crystal::RWLock that itself depends on GC, ...

The weirdest part is that it's working, and I have no idea how.
@ysbaddaden ysbaddaden self-assigned this Mar 5, 2024
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:runtime topic:multithreading labels Mar 5, 2024
@straight-shoota straight-shoota added this to the 1.12.0 milestone Mar 5, 2024
@straight-shoota straight-shoota merged commit e009a1e into crystal-lang:master Mar 6, 2024
57 checks passed
@straight-shoota straight-shoota changed the title Fix: Crystal::RWLock should be a struct Fix: Crystal::RWLock should be a struct Mar 6, 2024
@ysbaddaden ysbaddaden deleted the fix/gc-rwlock-is-a-class branch March 7, 2024 10:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:multithreading topic:stdlib:runtime
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants