Skip to content

Commit dea59ec

Browse files
committed
thread_variable? behaves strangely. Restore legacy NULL handling.
1 parent 95f5d94 commit dea59ec

File tree

3 files changed

+13
-7
lines changed

3 files changed

+13
-7
lines changed

lib/concurrent-ruby/concurrent/atomic/fiber_local_var.rb

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@ def initialize(default = nil, &default_block)
2020

2121
# @!macro thread_local_var_method_get
2222
def value
23-
Thread.current.fetch(@name) do
24-
Thread.current[@name] = default
25-
end
23+
Thread.current.fetch(@name) {default}
2624
end
2725

2826
# @!macro thread_local_var_method_set

lib/concurrent-ruby/concurrent/atomic/thread_local_var.rb

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,15 +23,23 @@ def initialize(default = nil, &default_block)
2323

2424
# @!macro thread_local_var_method_get
2525
def value
26-
if Thread.current.thread_variable?(@name)
27-
Thread.current.thread_variable_get(@name)
26+
value = Thread.current.thread_variable_get(@name)
27+
28+
if value.nil?
29+
default
30+
elsif value.equal?(NULL)
31+
nil
2832
else
29-
Thread.current.thread_variable_set(@name, default)
33+
value
3034
end
3135
end
3236

3337
# @!macro thread_local_var_method_set
3438
def value=(value)
39+
if value.nil?
40+
value = NULL
41+
end
42+
3543
Thread.current.thread_variable_set(@name, value)
3644
end
3745

spec/concurrent/atomic/thread_local_var_spec.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ module Concurrent
100100
end
101101

102102
it 'does not modify the value for other threads' do
103-
v.value = 2
103+
v.value = 3
104104

105105
b1 = CountDownLatch.new(2)
106106
b2 = CountDownLatch.new(2)

0 commit comments

Comments
 (0)