Files
news.gitea.happylizard.me/bin/gems/concurrent-ruby-1.3.8/lib/concurrent-ruby/concurrent/synchronization/safe_initialization.rb
T
pizza2d1 4cee170d66
Gitea Actions Demo / Explore-Gitea-Actions (push) Failing after 9s
Add bin and edit workflow
2026-09-16 13:11:16 -06:00

37 lines
1.1 KiB
Ruby

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