123456789_123456789_123456789_123456789_123456789_

Module: Concurrent::Synchronization::SafeInitialization

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Extended In:
Defined in: lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb

Overview

Note:

**Private Implementation:** This abstraction is a private, internal implementation detail. It should never be used directly.

By extending this module, a class and all its children are marked to be constructed safely. Meaning that all writes (ivar initializations) are made visible to all readers of newly constructed object. It ensures same behaviour as Java’s final fields.

Due to using Object#extend, the module is not included again if already present in the ancestors, which avoids extra overhead.

Examples:

class AClass < Concurrent::Synchronization::Object
  extend Concurrent::Synchronization::SafeInitialization

  def initialize
    @AFinalValue = 'value' # published safely, #foo will never return nil
  end

  def foo
    @AFinalValue
  end
end

Instance Method Summary

Instance Method Details

#new(*args, &block)

[ GitHub ]

  
# File 'lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb', line 29

def new(*args, &block)
  super(*args, &block)
ensure
  Concurrent::Synchronization.full_memory_barrier
end