class Concurrent::ThreadLocalVar

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.

This is similar to Ruby’s built-in thread-local variables (‘Thread#thread_variable_get`), but with these major advantages:

@!macro thread_safe_variable_comparison

@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