Actions
Feature #17513
openMethods of shareable objects and UnboundMethods should be shareable
Feature #17513:
Methods of shareable objects and UnboundMethods should be shareable
Description
class Foo
def foo
end
end
f = Foo.new.freeze
Ractor.shareable?(f) # => true
Ractor.make_shareable(f.method(:foo).to_proc) # => Proc, ok
Ractor.make_shareable(f.method(:foo)) # => Ractor::Error, expected Method
Ractor.make_shareable(Foo.instance_method(:foo)) # => Ractor::Error, expected UnboundMethod
Updated by Eregon (Benoit Daloze) about 5 years ago
Methods can be defined via define_method { capture_state } and so rely on mutable state, so I guess this is only OK for def methods.
Updated by marcandre (Marc-Andre Lafortune) about 5 years ago
Agreed, some methods can not be made shareable 👍.
Updated by jeremyevans0 (Jeremy Evans) over 2 years ago
- Tracker changed from Bug to Feature
- ruby -v deleted (
3.0.0p0) - Backport deleted (
2.5: UNKNOWN, 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN)
Updated by hsbt (Hiroshi SHIBATA) almost 2 years ago
- Status changed from Open to Assigned
Updated by trinistr (Alexander Bulancov) 10 days ago
A def-ed method of a shareable object may depend on unshareable state. Even worse, shareability of state may dynamically change:
module Checker
CHECK = []
def check?
CHECK.include?(self)
end
end
class A; include Checker; end
obj = A.new.freeze
Ractor.shareable?(obj) # => true
Ractor.new(obj) { |o| p o.check? } # Ractor::IsolationError
Checker::CHECK.freeze
Ractor.new(A.new.freeze) { |o| p o.check? } # false
Checker::CHECK = []
# And here we go again
Actions