Throw RuntimeError if getting/setting ractor local storage for non-main ractor
[Bug #19367]
This commit is contained in:
parent
7517d7629d
commit
c941fced21
Notes:
git
2025-05-13 11:18:23 +00:00
@ -1564,6 +1564,24 @@ assert_equal '1', %q{
|
||||
}.take
|
||||
}
|
||||
|
||||
# Ractor-local storage
|
||||
assert_equal '2', %q{
|
||||
Ractor.new {
|
||||
fails = 0
|
||||
begin
|
||||
Ractor.main[:key] # cannot get ractor local storage from non-main ractor
|
||||
rescue => e
|
||||
fails += 1 if e.message =~ /Cannot get ractor local/
|
||||
end
|
||||
begin
|
||||
Ractor.main[:key] = 'val'
|
||||
rescue => e
|
||||
fails += 1 if e.message =~ /Cannot set ractor local/
|
||||
end
|
||||
fails
|
||||
}.take
|
||||
}
|
||||
|
||||
###
|
||||
### Synchronization tests
|
||||
###
|
||||
|
10
ractor.rb
10
ractor.rb
@ -835,15 +835,21 @@ class Ractor
|
||||
end
|
||||
end
|
||||
|
||||
# get a value from ractor-local storage of current Ractor
|
||||
# get a value from ractor-local storage for current Ractor
|
||||
# Obsolete and use Ractor.[] instead.
|
||||
def [](sym)
|
||||
if (self != Ractor.current)
|
||||
raise RuntimeError, "Cannot get ractor local storage for non-current ractor"
|
||||
end
|
||||
Primitive.ractor_local_value(sym)
|
||||
end
|
||||
|
||||
# set a value in ractor-local storage of current Ractor
|
||||
# set a value in ractor-local storage for current Ractor
|
||||
# Obsolete and use Ractor.[]= instead.
|
||||
def []=(sym, val)
|
||||
if (self != Ractor.current)
|
||||
raise RuntimeError, "Cannot set ractor local storage for non-current ractor"
|
||||
end
|
||||
Primitive.ractor_local_value_set(sym, val)
|
||||
end
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user