summaryrefslogtreecommitdiff
path: root/ractor.c
AgeCommit message (Collapse)Author
2021-03-13merge revision(s) b3c53a8a885be8f5cc2b712798b0d2741c488ce4: [Backport #17672]NARUSE, Yui
Make Ractor stdio belonging to the Ractor [Bug #17672] Defer making ractor stdio until ractor started. Before ractor started, created objects belong to the caller ractor instead of the created ractor. --- bootstraptest/test_ractor.rb | 12 ++++++++++++ ractor.c | 9 --------- thread.c | 9 +++++++++ 3 files changed, 21 insertions(+), 9 deletions(-)
2021-03-12merge revision(s) 7b9476fbfab738d1eb01b4b4c4af9a1680513019: [Backport #17642]NARUSE, Yui
Ractor.allocate should not be allowed Ractor.allocate and Ractor#dup should not be allowed like Thread. [Bug #17642] --- bootstraptest/test_ractor.rb | 18 ++++++++++++++++++ ractor.c | 2 ++ 2 files changed, 20 insertions(+)
2021-01-13expose some C-APIs for ractorKoichi Sasada
expose some C-APIs to try to make ractor utilities on external gems. * add * rb_ractor_local_storage_value_lookup() to check availability * expose * rb_ractor_make_shareable() * rb_ractor_make_shareable_copy() * rb_proc_isolate() (not public) * rb_proc_isolate_bang() (not public) * rb_proc_ractor_make_shareable() (not public)
2020-12-24introduce rb_ractor_atfork()Koichi Sasada
to reset main ractor at fork().
2020-12-24fix ractor-locking around rb_ractor_thread_list()Koichi Sasada
With locking a ractor, rb_ary_push() can call RB_VM_LOCK_ENTER() and it violates an assertion: should not acquire ractor-lock.
2020-12-23Update rb_ractor_ensure_shareableNobuyoshi Nakada
* Fixed use of rb_ractor_shareable_p * Raise Ractor::IsolationError Notes: Merged: https://github.com/ruby/ruby/pull/3950
2020-12-23Changed shareable literal semantics [Feature #17397]Nobuyoshi Nakada
When `literal`, check if the literal about to be assigned to a constant is ractor-shareable, otherwise raise `Ractor::Error` at runtime instead of `SyntaxError`. Notes: Merged: https://github.com/ruby/ruby/pull/3950
2020-12-23ruby_single_main_ractor should be clear before warnKoichi Sasada
rb_warn can produce T_HASA object and it should not use transient heap.
2020-12-21Remove debugging codeMarc-Andre Lafortune
2020-12-22fix ractor's doc. [ci skip]Koichi Sasada
Notes: Merged: https://github.com/ruby/ruby/pull/3960
2020-12-22add Ractor#[]/#[]= for ractor local storageKoichi Sasada
This API is similar to plain old Thread#[]/Fiber#[] interface with symbol key. Notes: Merged: https://github.com/ruby/ruby/pull/3962
2020-12-22separate rb_ractor_pub from rb_ractor_tKoichi Sasada
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. Notes: Merged: https://github.com/ruby/ruby/pull/3943
2020-12-22TracePoint.new(&block) should be ractor-localKoichi Sasada
TracePoint should be ractor-local because the Proc can violate the Ractor-safe. Notes: Merged: https://github.com/ruby/ruby/pull/3943
2020-12-21Introduce Ractor::IsolationErrorKoichi Sasada
Ractor has several restrictions to keep each ractor being isolated and some operation such as `CONST="foo"` in non-main ractor raises an exception. This kind of operation raises an error but there is confusion (some code raises RuntimeError and some code raises NameError). To make clear we introduce Ractor::IsolationError which is raised when the isolation between ractors is violated. Notes: Merged: https://github.com/ruby/ruby/pull/3957
2020-12-21[DOC] Remove about FrozenError from Ractor::MovedObject [ci skip]Kazuhiro NISHIYAMA
Because unfreeze Ractor::MovedObject at https://github.com/ruby/ruby/commit/76e88480371469400346fca609efe67096813915
2020-12-21should use owned_p instead of locked_pKoichi Sasada
It should raise an error if the same thread tris to call receive/receive_if. Notes: Merged: https://github.com/ruby/ruby/pull/3949
2020-12-21rename to rb_ractor_make_shareable_copy()Koichi Sasada
from rb_ractor_make_copy_shareable().
2020-12-21fix Ractor.make_shareable() with Class/ModuleKoichi Sasada
To check shareable-ness, rb_ractor_shareable_p() is needed for Class/Module objects isntead of checking flags.
2020-12-19Tweak Ractor doc [doc] [ci skip]Marc-Andre Lafortune
2020-12-19Add documentation for Ractor (#3895)Victor Shepelev
Notes: Merged-By: marcandre <github@marc-andre.ca>
2020-12-19unfreeze Ractor::MovedObjectKoichi Sasada
Matz prefers to unfreeze the class. [Feature #17401]
2020-12-19add "copy: true" option for Ractor.make_shareableKoichi Sasada
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-18Use category: :experimental in warnings that are related to experimental ↵Jeremy Evans
features This adds rb_category_compile_warn in order to emit compiler warnings with categories. Note that Ripper currently ignores the category for these warnings, but by default it ignores the warnings completely, so this shouldn't matter. Notes: Merged: https://github.com/ruby/ruby/pull/3917
2020-12-17fix timing bugKoichi Sasada
ractor_sleep() can remain wait.status by interrupt, so that this patch handles more correctly. This patch fixed this kind of assertion failures: Assertion Failed: ../src/ractor.c:1332:ractor_yield_atexit:cr->sync.wait.status == wait_none
2020-12-16Ractor#receive_if to receive only matched messagesKoichi Sasada
Instead of Ractor.receive, Ractor.receive_if can provide a pattern by a block and you can choose the receiving message. [Feature #17378] Notes: Merged: https://github.com/ruby/ruby/pull/3862
2020-12-13Fixed a suspicious comparisonNobuyoshi Nakada
2020-12-09re-layout rb_ractor_tKoichi Sasada
separate synchronization data and ractor local data. Notes: Merged: https://github.com/ruby/ruby/pull/3858
2020-12-07fix Thread's interrupt and Ractor#take issueKoichi Sasada
Thread's interrupt set Ractor's wakeup_status as interrupted, but the status remains next Ractor communication API. This patch makes to ignore the previous interrupt state. [Bug #17366] Also this patch solves the Thread#kill and Ractor#take issues.
2020-12-07fix decl of ruby_single_main_ractorKoichi Sasada
On windows, MJIT doesn't work without this patch because of the declaration of ruby_single_main_ractor. This patch fix this issue and move the definition of it from ractor.c to vm.c to locate near place of ruby_current_vm_ptr. Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-07per-ractor object allocationKoichi Sasada
Now object allocation requires VM global lock to synchronize objspace. However, of course, it introduces huge overhead. This patch caches some slots (in a page) by each ractor and use cached slots for object allocation. If there is no cached slots, acquire the global lock and get new cached slots, or start GC (marking or lazy sweeping). Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-07cancel theap on multi-ractorsKoichi Sasada
accessing theap needs complicating synchronization but it reduce performance on multi-ractor mode. So simply stop using theap on multi-ractor mode. In future, theap should be replaced with more cleaver memory strategy. Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-07ruby_single_main_ractor for single ractor modeKoichi Sasada
ruby_multi_ractor was a flag that indicates the interpreter doesn't make any additional ractors (single ractor mode). Instead of boolean flag, ruby_single_main_ractor pointer is introduced which keeps main ractor's pointer if single ractor mode. If additional ractors are created, ruby_single_main_ractor becomes NULL. Notes: Merged: https://github.com/ruby/ruby/pull/3842
2020-12-04fix indexKoichi Sasada
`i` should not be used here because `i` will be `alen` when jumped here by "goto restart".
2020-12-02Skip checking Ractor recursive lockingTakashi Kokubun
for an MJIT worker thread. We can't do it because its GET_EC() returns NULL.
2020-12-01should not use rb_str_modify(), tooKoichi Sasada
Same as 8247b8edde, should not use rb_str_modify() here. https://bugs.ruby-lang.org/issues/17343#change-88858 Notes: Merged: https://github.com/ruby/ruby/pull/3833
2020-12-01rb_ext_ractor_safe() to declare ractor-safe extKoichi Sasada
C extensions can violate the ractor-safety, so only ractor-safe C extensions (C methods) can run on non-main ractors. rb_ext_ractor_safe(true) declares that the successive defined methods are ractor-safe. Otherwiwze, defined methods checked they are invoked in main ractor and raise an error if invoked at non-main ractors. [Feature #17307] Notes: Merged: https://github.com/ruby/ruby/pull/3824
2020-12-01should not use rb_ary_modify()Koichi Sasada
ractor_copy() used rb_ary_modify() to make sure this array is not sharing anything, but it also checks frozen flag. So frozen arrays raises an error. To solve this issue, this patch introduces new function rb_ary_cancel_sharing() which makes sure the array does not share another array and it doesn't check frozen flag. [Bug #17343] A test is quoted from https://github.com/ruby/ruby/pull/3817 Notes: Merged: https://github.com/ruby/ruby/pull/3831
2020-12-01ractor local storage C-APIKoichi Sasada
To manage ractor-local data for C extension, the following APIs are defined. * rb_ractor_local_storage_value_newkey * rb_ractor_local_storage_value * rb_ractor_local_storage_value_set * rb_ractor_local_storage_ptr_newkey * rb_ractor_local_storage_ptr * rb_ractor_local_storage_ptr_set At first, you need to create a key of storage by rb_ractor_local_(value|ptr)_newkey(). For ptr storage, it accepts the type of storage, how to mark and how to free with ractor's lifetime. rb_ractor_local_storage_value/set are used to access a VALUE and rb_ractor_local_storage_ptr/set are used to access a pointer. random.c uses this API. Notes: Merged: https://github.com/ruby/ruby/pull/3822
2020-11-30Fix `Ractor.make_shareable` for recursive structures with unfreezable componentsMarc-Andre Lafortune
Followup to #3823 Notes: Merged: https://github.com/ruby/ruby/pull/3827
2020-11-30Fixed Ractor.shareable? on cross-recursive objects [Bug #17344]Nobuyoshi Nakada
Notes: Merged: https://github.com/ruby/ruby/pull/3823 Merged-By: nobu <nobu@ruby-lang.org>
2020-11-27Use opaque struct pointer than voidNobuyoshi Nakada
2020-11-27mark default_randKoichi Sasada
default_rand can points a Bignum seed, so it should be marked.
2020-11-27per-ractor Random::DEFAULTKoichi Sasada
Random generators are not Ractor-safe, so we need to prepare per-ractor default random genearators. This patch set `Random::DEFAULT = Randm` (not a Random instance, but the Random class) and singleton methods like `Random.rand()` use a per-ractor random generator. [Feature #17322] Notes: Merged: https://github.com/ruby/ruby/pull/3813
2020-11-25fix error messageKoichi Sasada
2020-11-18fix public interfaceKoichi Sasada
To make some kind of Ractor related extensions, some functions should be exposed. * include/ruby/thread_native.h * rb_native_mutex_* * rb_native_cond_* * include/ruby/ractor.h * RB_OBJ_SHAREABLE_P(obj) * rb_ractor_shareable_p(obj) * rb_ractor_std*() * rb_cRactor and rm ractor_pub.h and rename srcdir/ractor.h to srcdir/ractor_core.h (to avoid conflict with include/ruby/ractor.h) Notes: Merged: https://github.com/ruby/ruby/pull/3775
2020-11-11ignore yield_atexit if outgoing port is closedKoichi Sasada
If outgoing_port is closed, Ractor.yield never successes. [Bug #17310] Notes: Merged: https://github.com/ruby/ruby/pull/3755
2020-11-11Threads in a ractor will be killed with the ractorKoichi Sasada
If a terminating ractor has child threads, then kill all child threads. Notes: Merged: https://github.com/ruby/ruby/pull/3754
2020-11-06a part of T_DATA object can Ractor#sendKoichi Sasada
T_DATA objects can refer unshareable objects and they should be copied recursively, however there is no way to replace with copied unshareable objects. However, if a T_DATA object refers only shareable objects, there is no need to replace. So this kind of T_DATA object (such as Time, Dir, File::Status and so on) can be sent by Ractor.send. Notes: Merged: https://github.com/ruby/ruby/pull/3739
2020-11-02strip trailing spaces [ci skip]Nobuyoshi Nakada
2020-11-02Copy for Ractor.send() without marshal.Koichi Sasada
Now copying objects do not need marshal protocol. Notes: Merged: https://github.com/ruby/ruby/pull/3728