Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Spawning processes should allow for borrowed captured data #75

Open
tqwewe opened this issue Sep 1, 2022 · 2 comments
Open

Spawning processes should allow for borrowed captured data #75

tqwewe opened this issue Sep 1, 2022 · 2 comments

Comments

@tqwewe
Copy link
Member

tqwewe commented Sep 1, 2022

Currently, trying to spawn a process requires you to clone captured data if you'd like to use it after the spawn. But because encoding data only requires a & reference, cloning should not be required.

Eg:

#[derive(Serialize, Deserialize)]
struct Foo {} // Doesn't implement clone

fn main() {
    let foo = Foo {};
    
    Process::spawn(&foo, |foo, _: Mailbox<()>| { ... }); // Fails, Deserialize is not implemented for `&Foo`, only `Foo`.
    Process::spawn(foo, |foo, _: Mailbox<()>| { ... });
    Process::spawn(foo, |foo, _: Mailbox<()>| { ... }); // fails, because foo was moved
}

It would be nice if spawn worked with both &foo and foo, so the change would not be breaking in any way.

@bkolobara
Copy link
Contributor

The issue are resources, they need to be owned when encoded. We could though explicitly clone them during serialisation.

There was also an idea of special serializers that send a reference to the process' memory, so that copies are completely avoided. In this case everything that is sent needs to be consumed, because now some other process owns part of your memory. To be forward compatible, I decided that captured data is owned. Not sure if we are getting this feature soon though.

If you serialize &Foo, can you deserialize it as Foo? What I mean is, from what are you borrowing the Foo inside the other process.

@tqwewe
Copy link
Member Author

tqwewe commented Sep 6, 2022

I see, that makes sense if the data really is semantically being moved to another process. I often imagined it was copied with serialization, but forward compatible reasons this makes sense.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants