diff options
| author | Koichi Sasada <ko1@atdot.net> | 2025-07-17 15:38:54 +0900 |
|---|---|---|
| committer | Koichi Sasada <ko1@atdot.net> | 2025-09-24 03:59:03 +0900 |
| commit | 55b1ba3bf276ba82173bd961fb8e0f08bf4182a6 (patch) | |
| tree | 9da723c4412af61ef221993fa021da97df9be1b0 /include/ruby/internal/encoding | |
| parent | c05ea920cef5991ca6163d12a436a61219a234a6 (diff) | |
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 should
* (1) refer shareable objects
* (2) be not be overwritten
```ruby
a = 42
Ractor.shareable_proc{ p a }
#=> OK
b = 43
Ractor.shareable_proc{ p b; b = 44 }
#=> Ractor::IsolationError because 'b' is reassigned in the block.
c = 44
Ractor.shareable_proc{ p c }
#=> Ractor::IsolationError because 'c' will be reassigned outside of the block.
c = 45
d = 45
d = 46 if cond
Ractor.shareable_proc{ p d }
#=> Ractor::IsolationError because 'd' was reassigned outside of the block.
```
The last `d`'s case can be relaxed in a future version.
The above check will be done in a static analysis at compile time,
so the reflection feature such as `Binding#local_varaible_set`
can not be detected.
```ruby
e = 42
shpr = Ractor.shareable_proc{ p e } #=> OK
binding.local_variable_set(:e, 43)
shpr.call #=> 42 (returns captured timing value)
```
Ractor.sharaeble_lambda is also introduced.
[Feature #21550]
[Feature #21557]
Diffstat (limited to 'include/ruby/internal/encoding')
0 files changed, 0 insertions, 0 deletions
