Object
@!visibility private
@!macro [attach] thread_local_var
A `ThreadLocalVar` is a variable where the value is different for each thread. Each variable may have a default value, but when you modify the variable only the current thread will ever see that change. @example v = ThreadLocalVar.new(14) v.value #=> 14 v.value = 2 v.value #=> 2 @example v = ThreadLocalVar.new(14) t1 = Thread.new do v.value #=> 14 v.value = 1 v.value #=> 1 end t2 = Thread.new do v.value #=> 14 v.value = 2 v.value #=> 2 end v.value #=> 14 @see https://docs.oracle.com/javase/7/docs/api/java/lang/ThreadLocal.html Java ThreadLocal
@!visibility private
@!visibility private
@!macro [attach] thread_local_var_method_initialize
Creates a thread local variable. @param [Object] default the default value when otherwise unset
# File lib/concurrent/atomic/thread_local_var.rb, line 48 def initialize(default = nil) @default = default allocate_storage end
@!macro [attach] thread_local_var_method_bind
Bind the given value to thread local storage during execution of the given block. @param [Object] value the value to bind @yield the operation to be performed with the bound variable @return [Object] the value
# File lib/concurrent/atomic/thread_local_var.rb, line 88 def bind(value, &block) if value.nil? stored_value = NIL_SENTINEL else stored_value = value end set(stored_value, &block) value end
@!macro [attach] thread_local_var_method_get
Returns the value in the current thread's copy of this thread-local variable. @return [Object] the current value
# File lib/concurrent/atomic/thread_local_var.rb, line 58 def value value = get if value.nil? @default elsif value == NIL_SENTINEL nil else value end end
@!macro [attach] thread_local_var_method_set
Sets the current thread's copy of this thread-local variable to the specified value. @param [Object] value the value to set @return [Object] the new value
# File lib/concurrent/atomic/thread_local_var.rb, line 76 def value=(value) bind value end
@!visibility private
# File lib/concurrent/atomic/thread_local_var.rb, line 103 def allocate_storage raise NotImplementedError end
Generated with the Darkfish Rdoc Generator 2.