Граф коммитов

39 Коммитов

Автор SHA1 Сообщение Дата
Koichi Sasada c9a9b8036c remove `Ractor::Selector` from Ruby level
`Ractor::Selector` is not approved by Matz so remove it from
Ruby-level.

The implementation is used by `Ractor.select` so most of implementation
was remaind and calling `rb_init_ractor_selector()`, `Ractor::Selector`
will be defined. I will provide `ractor-selector` gem to try it.
2023-12-16 01:00:01 +09:00
Koichi Sasada 5875fce6ce `Ractor::Selector#empty?`
It returns the waiting set is empty or not.

Also add Ractor::Selector's tests.
2023-03-03 00:08:02 +09:00
Koichi Sasada a4421bd73c Rewrite Ractor synchronization mechanism
This patch rewrites Ractor synchronization mechanism, send/receive
and take/yield.

* API
  * Ractor::Selector is introduced for lightweight waiting
    for many ractors.
* Data structure
  * remove `struct rb_ractor_waiting_list` and use
    `struct rb_ractor_queue takers_queue` to manage takers.
  * remove `rb_ractor_t::yield_atexit` and use
    `rb_ractor_t::sync::will_basket::type` to check the will.
  * add `rb_ractor_basket::p.take` to represent a taking ractor.
* Synchronization protocol
  * For the Ractor local GC, `take` can not make a copy object
    directly so ask to generate the copy from the yielding ractor.
  * The following steps shows what `r1.take` does on `r0`.
    * step1: (r0) register `r0` into `r1`'s takers.
    * step2: (r0) check `r1`'s status and wakeup r0 if `r1` is waiting
             for yielding a value.
    * step3: (r0) sleep until `r1` wakes up `r0`.
  * The following steps shows what `Ractor.yield(v)` on `r1`.
    * step1: (r1) check first takers of `r1` and if there is (`r0`),
             make a copy object of `v` and pass it to `r0` and
             wakes up `r0`.
    * step2: (r1) if there is no taker ractors, sleep until
             another ractor try to take.
2023-03-02 14:31:54 +09:00
John Bampton 2f7270c681
Fix spelling (#7389) 2023-02-27 09:56:06 -08:00
Luke Gruber 4ffef59bb1
[DOC] Make changes to docs in ractor.rb (#7180)
* Make changes to docs in ractor.rb

Mainly English changes to make things more clear, and to fix minor
non-idiomatic phrases. Also clarified difference between frozen and
shareable objects.

* More minor changes to Ractor docs.
2023-01-29 10:01:49 +09:00
Nobuyoshi Nakada 131c31a920
[Bug #19081] Show the caller location in warning for Ractor
The internal location in ractor.rb is not usefull at all.
```
$ ruby -e 'Ractor.new {}'
<internal:ractor>:267: warning: Ractor is experimental, ...
```
2022-10-26 19:43:14 +09:00
Felix Yan 1486ffe039
[DOC] Correct article of Ractor's introduction [ci skip] 2022-08-28 16:27:11 +09:00
Nobuyoshi Nakada 94c3d528e7
Fix conversion of `rb_ractor_id()` 2022-07-28 23:46:07 +09:00
Nobuyoshi Nakada a27c274f04
[DOC] Fix broken links [ci skip]
* As the "doc/" prefix is specified by the `--page-dir` option,
  remove from the rdoc references.
* Refer to the original .rdoc instead of the converted .html.
2021-09-15 14:16:14 +09:00
S-H-GAMELINKS bdd6d8746f Replace RBOOL macro 2021-09-05 23:01:27 +09:00
Ryuta Kamizono 33f2ff3bab Fix some typos by spell checker 2021-04-26 10:07:41 +09:00
Tom Chen 8187228de0
Fix ractor docs (#4048) [doc] 2021-01-10 15:39:37 -05:00
Marc-Andre Lafortune a76082f499 Add call-seq to Ractor doc; improve wording [doc] 2020-12-24 02:19:37 -05:00
nagachika 831f785068 [DOC] Fix typo in Ractor.make_shareable documentation. 2020-12-22 08:08:27 +09:00
Koichi Sasada c34c6a89cb fix ractor's doc. [ci skip] 2020-12-22 06:09:42 +09:00
Koichi Sasada d0e4ccbefc add Ractor.main
It returns main Ractor, like Thread.main.
[Feature #17418]
2020-12-22 05:54:14 +09:00
Koichi Sasada 35471a9487 add Ractor#[]/#[]= for ractor local storage
This API is similar to plain old Thread#[]/Fiber#[] interface
with symbol key.
2020-12-22 05:26:32 +09:00
Marc-Andre Lafortune 8f2031a067 Ractor#to_s as #inspect 2020-12-21 13:31:00 -05:00
Koichi Sasada 02d9524cda separate rb_ractor_pub from rb_ractor_t
separate some fields from rb_ractor_t to rb_ractor_pub and put it
at the beggining of rb_ractor_t and declare it in vm_core.h so
vm_core.h can access rb_ractor_pub fields.

Now rb_ec_ractor_hooks() is a complete inline function and no
MJIT related issue.
2020-12-22 00:03:00 +09:00
Koichi Sasada 7600f69a8e rename to rb_ractor_make_shareable_copy()
from rb_ractor_make_copy_shareable().
2020-12-21 02:21:33 +09:00
Nobuyoshi Nakada b911509a08
Adjusted indents of closing braces [ci skip] 2020-12-20 15:13:25 +09:00
Koichi Sasada 7f8108eeff fix indent 2020-12-20 04:51:00 +09:00
Victor Shepelev 1f565ac6d9
Add documentation for Ractor (#3895) 2020-12-19 13:04:40 -05:00
Nobuyoshi Nakada 5c9d6ea6b4
Strip trailing spaces [ci skip] 2020-12-19 15:34:37 +09:00
Koichi Sasada 80cb9165fa add "copy: true" option for Ractor.make_shareable
Ractor.make_shareable(obj) tries to make obj a shareable object
by changing the attribute of obj and traversable objects from obj
(mainly freeze them).

"copy: true" option is more conservative approach by make deep
copied object and make it sharable. It doesn't affect any existing
objects.
2020-12-19 05:52:18 +09:00
Marc-Andre Lafortune d5929b39a9 Make Ractor#receive_if private 2020-12-16 10:42:17 -05:00
Koichi Sasada a9a7f4d8b8 Ractor#receive_if to receive only matched messages
Instead of Ractor.receive, Ractor.receive_if can provide a pattern
by a block and you can choose the receiving message.

[Feature #17378]
2020-12-16 19:12:48 +09:00
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