ri > Concurrent::ThreadLocalVar

๐Ÿงต Concurrent::ThreadLocalVar < ThreadLocalVarImplementation

๐Ÿ“ NAME

Concurrent::ThreadLocalVar โ€” A thread-local variable with perโ€‘thread values.

๐Ÿš€ Quick Reference

Use CaseCommandDescription
Create a threadโ€‘local variable with default valueThreadLocalVar.new(14)Initializes a new variable; each thread sees the default value unless modified.
Read current threadโ€™s valuev.valueReturns the value for the calling thread.
Set current threadโ€™s valuev.value = 2Changes the value only for the current thread; other threads are unaffected.
Demonstrate isolation across threadsThread.new { v.value = 1 }Each thread can independently modify its own copy of the variable.

๐Ÿ“– DESCRIPTION

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

๐Ÿ”น Basic usage

v = ThreadLocalVar.new(14)
v.value #=> 14
v.value = 2
v.value #=> 2

๐Ÿ”น Thread isolation

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

Concurrent::ThreadLocalVar
๐Ÿงต Concurrent::ThreadLocalVar < ThreadLocalVarImplementation ๐Ÿ“ NAME ๐Ÿš€ Quick Reference ๐Ÿ“– DESCRIPTION ๐Ÿ’ก EXAMPLES
๐Ÿ”น Basic usage ๐Ÿ”น Thread isolation
๐Ÿ”— SEE ALSO

Generated by phpman v4.9.26-1-g511901d · Markdown · JSON · MCP Author: Che Dong Under GNU General Public License
2026-07-28 01:04 @216.73.217.25
CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 Transitional!Valid CSS!
Enhanced by LLM: deepseek-v4-flash / taotoken.net / www.chedong.com - original format