Skip to content

Ractor shareable proc #13926

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Ractor shareable proc #13926

wants to merge 2 commits into from

Conversation

ko1
Copy link
Contributor

@ko1 ko1 commented Jul 17, 2025

Ractor.shareable_proc

call-seq:
Ractor.sharable_proc(self: nil){} -> sharable proc

It returns shareable Proc object. The Proc object is
shareable and the self in a block will be replaced with
the value passed via self: keyword.

In a shareable Proc, the outer variables are read-only
and the outer variables should point only shareable objects.

    a = 42
    b = []
    Ractor.shareable_proc{ p a }.call # ok
    Ractor.shareable_proc{ p b }
    #=> can not make shareable Proc because it can refer unshareable object [] from variable 'b' (Ractor::IsolationError)

Ractor.sharaeble_lambda is also introduced.

Ractor.make_sharable(a_proc) is no longer supported.

[Feature #21039]

@ko1 ko1 force-pushed the ractor_shareable_proc branch 3 times, most recently from 43a14f6 to f05ec1f Compare July 17, 2025 08:49
ko1 added 2 commits July 17, 2025 18:50
```ruby
def f self:nil
  Primitive.cexpr! %q{ self_keyword_parameter }
end
```

This patch allows to acess to `self:` keyword parameter with
`self_keyword_parameter` (C's) variable name in `cexpr!` like above.
call-seq:
  Ractor.sharable_proc(self: nil){} -> sharable proc

It returns shareable Proc object. The Proc object is
shareable and the self in a block will be replaced with
the value passed via `self:` keyword.

In a shareable Proc, the outer variables are read-only
and the outer variables should point only shareable objects.

```
    a = 42
    b = []
    Ractor.shareable_proc{ p a }.call # ok
    Ractor.shareable_proc{ p b }
    #=> can not make shareable Proc because it can refer unshareable object [] from variable 'b' (Ractor::IsolationError)
```

Ractor.sharaeble_lambda is also introduced.

Ractor.make_sharable(a_proc) is no longer supported.

[Feature #21039]
@ko1 ko1 force-pushed the ractor_shareable_proc branch from f05ec1f to 50b94b7 Compare July 17, 2025 09:50
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

Successfully merging this pull request may close these issues.

1 participant
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy