summaryrefslogtreecommitdiff
path: root/ractor_sync.c
AgeCommit message (Collapse)Author
38 hoursSuppress warningsNobuyoshi Nakada
- `ractor_sync_terminate_atfork` is unused unless fork is working - `cr` in `vm_lock_leave` is only for debugging
5 daysAdd write barriers from Ractor::Port to RactorJohn Hawthorn
Ractor::Port will mark the ractor, so we must issue a write barrier. This was detected by wbcheck, but we've also seen it in CI: verify_internal_consistency_reachable_i: WB miss (O->Y) 0x000071507d8bff80 ractor/port/Ractor::Port ractor/port -> 0x0000715097f5a470 ractor/Ractor r:1 <internal:kernel>:48: [BUG] gc_verify_internal_consistency: found internal inconsistency. Notes: Merged: https://.com/ruby/ruby/pull/13644
11 daysFix memory of Ractor basket when sending to closed RactorPeter Zhu
The following script s memory: r = Ractor.new { } r.value 10.times do 100_000.times do r.send(123) rescue Ractor::ClosedError end puts `ps -o rss= -p #{$$}` end Before: 18508 25420 32460 40012 47308 54092 61132 68300 75724 83020 After: 11432 11432 11432 11432 11432 11432 11432 11432 11432 11688 Notes: Merged: https://.com/ruby/ruby/pull/13590
2025-06-03Fix memory of Ractor portsPeter Zhu
Memory reported: 3 miniruby 0x1044b6c1c ractor_init + 164 ractor.c:460 2 miniruby 0x1043fd6a0 ruby_xmalloc + 44 gc.c:5188 1 miniruby 0x104402840 rb_gc_impl_malloc + 148 default.c:8140 0 libsystem_malloc.dylib 0x19ab3912c _malloc_zone_malloc_instrumented_or_legacy + 152 Notes: Merged: https://.com/ruby/ruby/pull/13504
2025-06-03Fix memory of Ractor recv_queuePeter Zhu
Memory reported: 3 miniruby 0x104702c1c ractor_init + 164 ractor.c:460 2 miniruby 0x1046496a0 ruby_xmalloc + 44 gc.c:5188 1 miniruby 0x10464e840 rb_gc_impl_malloc + 148 default.c:8140 0 libsystem_malloc.dylib 0x19ab3912c _malloc_zone_malloc_instrumented_or_legacy + 152 Notes: Merged: https://.com/ruby/ruby/pull/13504
2025-05-31prepare IDs for `Ractor::monitor`Koichi Sasada
To prevent the following strange error, prepare IDs at first. ``` <internal:ractor>:596:in 'Ractor#monitor': symbol :exited is already registered with 98610c (fatal) from <internal:ractor>:550:in 'Ractor#join' from <internal:ractor>:574:in 'Ractor#value' from bootstraptest.test_ractor.rb_2013_1309.rb:12:in '<main>' ``` BTW, the error should be fixed on ID management system. Notes: Merged: https://.com/ruby/ruby/pull/13481
2025-05-31`Ractor::Port`Koichi Sasada
* Added `Ractor::Port` * `Ractor::Port#receive` (support multi-threads) * `Rcator::Port#close` * `Ractor::Port#closed?` * Added some methods * `Ractor#join` * `Ractor#value` * `Ractor#monitor` * `Ractor#unmonitor` * Removed some methods * `Ractor#take` * `Ractor.yield` * Change the spec * `Racotr.select` You can wait for multiple sequences of messages with `Ractor::Port`. ```ruby ports = 3.times.map{ Ractor::Port.new } ports.map.with_index do |port, ri| Ractor.new port,ri do |port, ri| 3.times{|i| port << "r#{ri}-#{i}"} end end p ports.each{|port| pp 3.times.map{port.receive}} ``` In this example, we use 3 ports, and 3 Ractors send messages to them respectively. We can receive a series of messages from each port. You can use `Ractor#value` to get the last value of a Ractor's block: ```ruby result = Ractor.new do heavy_task() end.value ``` You can wait for the termination of a Ractor with `Ractor#join` like this: ```ruby Ractor.new do some_task() end.join ``` `#value` and `#join` are similar to `Thread#value` and `Thread#join`. To implement `#join`, `Ractor#monitor` (and `Ractor#unmonitor`) is introduced. This commit changes `Ractor.select()` method. It now only accepts ports or Ractors, and returns when a port receives a message or a Ractor terminates. We removes `Ractor.yield` and `Ractor#take` because: * `Ractor::Port` supports most of similar use cases in a simpler manner. * Removing them significantly simplifies the code. We also change the internal thread scheduler code (thread_pthread.c): * During barrier synchronization, we keep the `ractor_sched` lock to avoid deadlocks. This lock is released by `rb_ractor_sched_barrier_end()` which is called at the end of operations that require the barrier. * fix potential deadlock issues by checking interrupts just before setting UBF. https://bugs.ruby-lang.org/issues/21262 Notes: Merged: https://.com/ruby/ruby/pull/13445