### Home Classes Methods

### In Files

- lib/thread_safe/util/volatile_tuple.rb

### Parent

Object

### Methods

- ::new
- #cas
- #compare_and_set
- #each
- #size
- #volatile_get
- #volatile_set

### Included Modules

- Enumerable

### Class/Module Index

Quicksearch

- ThreadSafe
- ThreadSafe::Array
- ThreadSafe::AtomicReferenceCacheBackend
- ThreadSafe::AtomicReferenceCacheBackend::Node
- ThreadSafe::AtomicReferenceCacheBackend::Table
- ThreadSafe::Cache
- ThreadSafe::Hash
- ThreadSafe::MriCacheBackend
- ThreadSafe::NonConcurrentCacheBackend
- ThreadSafe::SynchronizedCacheBackend
- ThreadSafe::Util
- ThreadSafe::Util::Adder
- ThreadSafe::Util::CheapLockable
- ThreadSafe::Util::PowerOfTwoTuple
- ThreadSafe::Util::Striped64
- ThreadSafe::Util::Striped64::Cell
- ThreadSafe::Util::Volatile
- ThreadSafe::Util::VolatileTuple
- ThreadSafe::Util::XorShiftRandom
- SynchronizedDelegator
- Threadsafe

No matching classes.

# ThreadSafe::Util::VolatileTuple

A fixed size array with volatile volatile getters/setters. Usage:

    arr = VolatileTuple.new(16)
    arr.volatile_set(0, :foo)
    arr.volatile_get(0)    # => :foo
    arr.cas(0, :foo, :bar) # => true
    arr.volatile_get(0)    # => :bar

### Constants

Tuple

### Public Class Methods

new(size) click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 15
    def initialize(size)
      @tuple = tuple = Tuple.new(size)
      i = 0
      while i < size
        tuple[i] = AtomicReference.new
        i += 1
      end
    end

### Public Instance Methods

cas(i, old_value, new_value) click to toggle source
Alias for: compare_and_set
compare_and_set(i, old_value, new_value) click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 32
    def compare_and_set(i, old_value, new_value)
      @tuple[i].compare_and_set(old_value, new_value)
    end

Also aliased as: cas
each() click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 41
    def each
      @tuple.each {|ref| yield ref.get}
    end

size() click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 37
    def size
      @tuple.size
    end

volatile_get(i) click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 24
    def volatile_get(i)
      @tuple[i].get
    end

volatile_set(i, value) click to toggle source

    # File lib/thread_safe/util/volatile_tuple.rb, line 28
    def volatile_set(i, value)
      @tuple[i].set(value)
    end

[Validate]

Generated with the Darkfish Rdoc Generator 2.