Class: Concurrent::ThreadLocalVar

Inherits:
ThreadLocalVarImplementation
  • Object
show all
Defined in:
lib/concurrent/atomic/thread_local_var.rb

Overview

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.

Examples:

v = ThreadLocalVar.new(14)
v.value #=> 14
v.value = 2
v.value #=> 2
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 Also: