Class: Tool::ThreadLocal
- Inherits:
-
Delegator
- Object
- Delegator
- Tool::ThreadLocal
- Defined in:
- lib/tool/thread_local.rb
Overview
Have thread local values without them actually being thread global.
Advantages:
-
values for all threads are garbage collected when ThreadLocal instance is
-
values for specific thread are garbage collected when thread is
-
no hidden global state
-
supports other data types besides hashes.
Instance Method Summary collapse
-
#initialize(default = {}) ⇒ ThreadLocal
constructor
A new instance of ThreadLocal.
Constructor Details
#initialize(default = {}) ⇒ ThreadLocal
Returns a new instance of ThreadLocal.
32 33 34 35 36 |
# File 'lib/tool/thread_local.rb', line 32 def initialize(default = {}) @mutex = Mutex.new @default = default.dup @map = {} end |