Module: ThreadSafe::Util::CheapLockable
- Extended by:
- Volatile
- Included in:
- AtomicReferenceCacheBackend::Node
- Defined in:
- lib/thread_safe/util/cheap_lockable.rb
Overview
Provides a cheapest possible (mainly in terms of memory usage) Mutex
with the ConditionVariable bundled in.
Usage:
class A
include CheapLockable
def do_exlusively
cheap_synchronize { yield }
end
def wait_for_something
cheap_synchronize do
cheap_wait until resource_available?
do_something
cheap_broadcast # wake up others
end
end
end
Class Method Summary collapse
-
.attr_volatile(*attr_names) ⇒ Object
extended
from Volatile
Provides
volatile(in the JVM's sense) attribute accessors implemented atop of the +AtomicReference+s.
Class Method Details
.attr_volatile(*attr_names) ⇒ Object Originally defined in module Volatile
Provides volatile (in the JVM's sense) attribute accessors implemented
atop of the +AtomicReference+s.
Usage:
class Foo
extend ThreadSafe::Util::Volatile
attr_volatile :foo, :bar
def initialize()
super() # must super() into parent initializers before using the volatile attribute accessors
self. =
end
def hello
my_foo = foo # volatile read
self.foo = 1 # volatile write
cas_foo(1, 2) # => true | a strong CAS
end
end