Sha256: c0ef81b9c94b732dece30ab11125b1d1f14317d948a634693a7d0ecd1b19d2f1

Contents?: true

Size: 1.1 KB

Versions: 103

Compression:

Stored size: 1.1 KB

Contents

require 'concurrent/synchronization/full_memory_barrier'

module Concurrent
  module Synchronization

    # @!visibility private
    # @!macro internal_implementation_note
    #
    # 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 Kernel#extend, the module is not included again if already present in the ancestors,
    # which avoids extra overhead.
    #
    # @example
    #   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
    module SafeInitialization
      def new(*args, &block)
        super(*args, &block)
      ensure
        Concurrent::Synchronization.full_memory_barrier
      end
    end
  end
end

Version data entries

103 entries across 103 versions & 16 rubygems

Version Path
harbr-0.2.8 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.7 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.6 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.5 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.4 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.3 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.2 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.1 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.2.0 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.99 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.98 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.97 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.96 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.95 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.94 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.93 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.91 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.90 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.89 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
harbr-0.1.88 vendor/bundle/ruby/3.2.0/gems/concurrent-ruby-1.2.2/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb