Class: Concurrent::AtomicFixnum
- Inherits:
-
AtomicFixnumImplementation
- Object
- Concurrent::AtomicFixnum
- Defined in:
- lib/concurrent/atomic/atomic_fixnum.rb
Overview
A numeric value that can be updated atomically. Reads and writes to an atomic fixnum and thread-safe and guaranteed to succeed. Reads and writes may block briefly but no explicit locking is required.
Testing with ruby 2.1.2 Testing with Concurrent::MutexAtomicFixnum…
3.130000 0.000000 3.130000 ( 3.136505)
Testing with Concurrent::CAtomicFixnum…
0.790000 0.000000 0.790000 ( 0.785550)
Testing with jruby 1.9.3 Testing with Concurrent::MutexAtomicFixnum…
5.460000 2.460000 7.920000 ( 3.715000)
Testing with Concurrent::JavaAtomicFixnum…
4.520000 0.030000 4.550000 ( 1.187000)
Instance Method Summary collapse
-
#compare_and_set(expect, update) ⇒ Fixnum
Atomically sets the value to the given updated value if the current value == the expected value.
-
#decrement ⇒ Fixnum
Decreases the current value by the given amount (defaults to 1).
-
#increment ⇒ Fixnum
Increases the current value by the given amount (defaults to 1).
-
#initialize(initial = 0) ⇒ Object
constructor
Creates a new ‘AtomicFixnum` with the given initial value.
-
#update {|Object| ... } ⇒ Object
Pass the current value to the given block, replacing it with the block’s result.
-
#value ⇒ Fixnum
Retrieves the current ‘Fixnum` value.
-
#value=(value) ⇒ Fixnum
Explicitly sets the value.
Constructor Details
#initialize(initial = 0) ⇒ Object
Creates a new ‘AtomicFixnum` with the given initial value.
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
Instance Method Details
#compare_and_set(expect, update) ⇒ Fixnum
Atomically sets the value to the given updated value if the current value == the expected value.
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
#decrement ⇒ Fixnum
Decreases the current value by the given amount (defaults to 1).
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
#increment ⇒ Fixnum
Increases the current value by the given amount (defaults to 1).
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
#update {|Object| ... } ⇒ Object
Pass the current value to the given block, replacing it with the block’s result. May retry if the value changes during the block’s execution.
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
#value ⇒ Fixnum
Retrieves the current ‘Fixnum` value.
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |
#value=(value) ⇒ Fixnum
Explicitly sets the value.
131 132 |
# File 'lib/concurrent/atomic/atomic_fixnum.rb', line 131 class AtomicFixnum < AtomicFixnumImplementation end |