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 circular dependency between AtomicReference and Synchronization::Object #982

Conversation

eregon
Copy link
Collaborator

@eregon eregon commented Jan 8, 2023

  • Do not depend on Synchronization::LockableObject for MutexAtomic{Reference,Fixnum,Boolean}
  • Extract safe initialization and use it for MutexAtomic{Reference,Fixnum,Boolean}

TODO:

  • Check what gets defined by the JRuby extension, might need more require 'concurrent/utility/native_extension_loader' # load native parts first for JRuby
  • Audit usages of java_extensions_loaded?

eregon added 5 commits January 8, 2023 21:02
…Object

* Specifically, the cycle is:
  Synchronization::Object -> AtomicReference (through generated code for #__initialize_atomic_fields__ used by #initialize)
  AtomicReference -> MutexAtomicReference (only for cruby no exts and unknown ruby)
  MutexAtomicReference -> Synchronization::LockableObject
  Synchronization::LockableObject -> MutexLockableObject, JRubyLockableObject, MonitorLockableObject
  MutexLockableObject -> AbstractLockableObject
  AbstractLockableObject -> Synchronization::Object

  As an example AtomicMarkableReference -> Synchronization::Object uses it
  and so the requires of spec/concurrent/atomic/atomic_markable_reference_spec.rb
  cannot be fixed before this.
* This also avoids allocating a ConditionVariable for MutexAtomicReference.
…an and MutexAtomicFixnum

* Similar to MutexAtomicReference.
* Avoids allocating an extra ConditionVariable.
* Ensure the native extension version is used on CRuby in specs.
…um,Boolean}

* The previous logic risked a thread seeing @__Lock__ being nil
  if the object was published racily.
* Avoids relying on the precise semantics of #extend.
@eregon eregon force-pushed the fix-cycle-AtomicReference-Synchronization-Object branch from 54a9975 to 973f1e6 Compare January 8, 2023 20:31
@eregon eregon force-pushed the fix-cycle-AtomicReference-Synchronization-Object branch from b574b30 to f3d8a89 Compare January 11, 2023 15:49
@eregon eregon merged commit eac0237 into ruby-concurrency:master Jan 11, 2023
@eregon eregon deleted the fix-cycle-AtomicReference-Synchronization-Object branch January 11, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Officially support requiring subparts of concurrent-ruby, e.g., require 'concurrent/map'
1 participant