1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
Commit graph

12 commits

Author SHA1 Message Date
Koichi Sasada
0a52161872 fix Ractor#receive by other ractors
Ractor#receive can be called by the another Ractors using send,
so making this method completely same as `Ractor.receive` even if
the ractor is specified by the receiver (OO term :p).
2020-12-16 17:18:13 +09:00
Nobuyoshi Nakada
65450e8f7d Call FrozenCore.make_shareable 2020-12-14 19:19:16 +09:00
Nobuyoshi Nakada
f43c71abe0 Implemented shareable_constant_value
It does shallow freeze only for now.
2020-12-14 19:19:16 +09:00
Marc-Andre Lafortune
53ce71b5af Ractor.select requires an argument or yield_value 2020-12-07 02:21:12 -05:00
Koichi Sasada
fa3670e6e4 remove Ractor#close
close_incoming by antoher ractor means there is no other messages
will be sent to the ractor, so Ractor.receive will block forever,
and it should raise and stop.

close_outgoing by antoher ractor means, ... I don't have good idea
to use it. It can be a private method.

Ractor#close calls both, but it does not make sense to call
different purpose methods, so I remove it.
2020-11-11 18:11:09 +09:00
Marc-Andre Lafortune
bd6cd85155 Tweak return of Ractor#close, add doc 2020-10-30 15:22:18 -04:00
Koichi Sasada
2f50936cb9 Ractor.make_shareable(obj)
Introduce new method Ractor.make_shareable(obj) which tries to make
obj shareable object. Protocol is here.

(1) If obj is shareable, it is shareable.
(2) If obj is not a shareable object and if obj can be shareable
    object if it is frozen, then freeze obj. If obj has reachable
    objects (rs), do rs.each{|o| Ractor.make_shareable(o)}
    recursively (recursion is not Ruby-level, but C-level).
(3) Otherwise, raise Ractor::Error. Now T_DATA is not a shareable
    object even if the object is frozen.

If the method finished without error, given obj is marked as
a sharable object.

To allow makng a shareable frozen T_DATA object, then set
`RUBY_TYPED_FROZEN_SHAREABLE` as type->flags. On default,
this flag is not set. It means user defined T_DATA objects are
not allowed to become shareable objects when it is frozen.

You can make any object  shareable by setting FL_SHAREABLE flag,
so if you know that the T_DATA object is shareable (== thread-safe),
set this flag, at creation time for example. `Ractor` object is one
example, which is not a frozen, but a shareable object.
2020-10-21 07:59:24 +09:00
Koichi Sasada
2bdbdc1580 add Ractor.shareable?(obj)
This method returns obj is shareable or not.
2020-10-20 15:39:37 +09:00
MSP-Greg
c6652f223c ractor.rb - indent comment code [ci skip] 2020-10-12 13:56:11 +09:00
Benoit Daloze
bfc1c7205d Add Ractor#receive and Ractor.receive and use it in all places
* Keep Ractor#recv/Ractor.recv as an alias for now.
2020-10-10 12:48:09 +02:00
Quang-Minh Nguyen
d5fa66156a Add status to Ractor#inspect 2020-09-20 23:10:44 +09:00
Koichi Sasada
79df14c04b Introduce Ractor mechanism for parallel execution
This commit introduces Ractor mechanism to run Ruby program in
parallel. See doc/ractor.md for more details about Ractor.
See ticket [Feature #17100] to see the implementation details
and discussions.

[Feature #17100]

This commit does not complete the implementation. You can find
many bugs on using Ractor. Also the specification will be changed
so that this feature is experimental. You will see a warning when
you make the first Ractor with `Ractor.new`.

I hope this feature can help programmers from thread-safety issues.
2020-09-03 21:11:06 +09:00