class Concurrent::MutexAtomicFixnum
@see docs.oracle.com/javase/7/docs/api/java/util/concurrent/atomic/AtomicLong.html java.util.concurrent.atomic.AtomicLong
@since 0.5.0
briefly but no explicit locking is required.
fixnum and thread-safe and guaranteed to succeed. Reads and writes may block
A numeric value that can be updated atomically. Reads and writes to an atomic
@!macro [attach] atomic_fixnum
def compare_and_set(expect, update)
-
(Boolean)
- true if the value was updated else false
Parameters:
-
update
(Fixnum
) -- the new value -
expect
(Fixnum
) -- the expected value
def compare_and_set(expect, update) @mutex.lock if @value == expect @value = update result = true else result = false end @mutex.unlock result end
def decrement
-
(Fixnum)
- the current value after decrementation
def decrement @mutex.lock @value -= 1 result = @value @mutex.unlock result end
def increment
-
(Fixnum)
- the current value after incrementation
def increment @mutex.lock @value += 1 result = @value @mutex.unlock result end
def initialize(init = 0)
-
(ArgumentError)
- if the initial value is not a `Fixnum`
Parameters:
-
init
(Fixnum
) -- the initial value
def initialize(init = 0) raise ArgumentError.new('initial value must be a Fixnum') unless init.is_a?(Fixnum) @value = init @mutex = Mutex.new end
def value
-
(Fixnum)
- the current value
def value @mutex.lock result = @value @mutex.unlock result end
def value=(value)
-
(ArgumentError)
- if the new value is not a `Fixnum`
Returns:
-
(Fixnum)
- the current value
Parameters:
-
value
(Fixnum
) -- the new value to be set
def value=(value) raise ArgumentError.new('value must be a Fixnum') unless value.is_a?(Fixnum) @mutex.lock result = @value = value @mutex.unlock result end