Project

General

Profile

Actions

Feature #17404

open

Ractor `move:` API to allow shareability check

Added by marcandre (Marc-Andre Lafortune) almost 4 years ago. Updated 8 months ago.

Status:
Assigned
Target version:
-
[ruby-core:101499]

Description

I'd like to ractor.send(message) and express that message should be shareable. Currently I'm given two choices: move: true and move: false / nothing, neither of which have an effect if my message is shareable, and neither of which will tell me in case there's a bug in my program and message is not shareable.

Could we consider a slightly different API (for 3.0 or 3.1)?

ractor.send(message, pass: :copy) # => like current `move: false`
ractor.send(message, pass: :move) # => like current `move: true`
ractor.send(message, pass: :share) # => raise in case message is not shareable
ractor.send(message) # => same as `pass: :copy`

Updated by ko1 (Koichi Sasada) almost 4 years ago

#send_ref(message) and raise an error if message is not a sharable?

Updated by marcandre (Marc-Andre Lafortune) almost 4 years ago

ko1 (Koichi Sasada) wrote in #note-1:

#send_ref(message) and raise an error if message is not a sharable?

There would be an easy way to deep-copy or deep-move an object, right? If you mean that the default should be pass: :share, then that seems fine by me.

We have to consider impact for passing arguments to Ractor.new(...). Right now these are copied; would it also raise if the arguments are not shareable? Would you add pass: option there too (see #17286)?

Updated by ko1 (Koichi Sasada) almost 4 years ago

marcandre (Marc-Andre Lafortune) wrote in #note-2:

ko1 (Koichi Sasada) wrote in #note-1:

#send_ref(message) and raise an error if message is not a sharable?

There would be an easy way to deep-copy or deep-move an object, right? If you mean that the default should be pass: :share, then that seems fine by me.

not sure what you mean. I mean:

def send_ref(obj)
  raise unless Ractor.shareable?(obj)
  send(obj)
end

We have to consider impact for passing arguments to Ractor.new(...). Right now these are copied; would it also raise if the arguments are not shareable? Would you add pass: option there too (see #17286)?

I guess it is different topic.

Updated by marcandre (Marc-Andre Lafortune) almost 4 years ago

Oh, sorry, I didn't see the _ref part. So you are proposing a different method. In my mind, they are all ways of sending a message, it's just a question of method to cross the Ractor frontier. move/copy/has-cross-border-visa 😅

Otherwise we could have Ractor#move, Ractor#copy and Ractor#send, but seems to me like one method with one keyword (pass, via or transfer) is best API.

It also seems strange to write send_ref(true) or send_ref(42)...

Did Matz say anything about API?

Actions #5

Updated by hsbt (Hiroshi SHIBATA) 8 months ago

  • Status changed from Open to Assigned
Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0Like0