Project

General

Profile

Actions

Feature #22441

closed

Add Ractor#alive?

Feature #22441: Add Ractor#alive?

Added by jhawthorn (John Hawthorn) about 2 months ago. Updated about 1 month ago.

Status:
Closed
Assignee:
-
Target version:
-
[ruby-core:127109]

Description

I propose adding Ractor#alive? as a non-blocking way to ask whether a Ractor has finished. This matches Thread#alive?/Fiber#alive?.

r = Ractor.new { Ractor.receive }
r.alive? #=> true
r << :done
r.join
r.alive? #=> false

This is already somewhat visible via Ractor#inspect, but that's quite awkward. We use this in the test suite.

r = Ractor.new{ sleep 1 }
r.inspect #=> "#<Ractor:#3 (irb):4 running>"
sleep 2
r.inspect #=> "#<Ractor:#3 (irb):4 terminated>"

After fork, other Ractors alive? will return false, as with Thread#alive?.

https://github.com/ruby/ruby/pull/19349

Updated by jhawthorn (John Hawthorn) about 2 months ago Actions #1

  • Description updated (diff)

Updated by ko1 (Koichi Sasada) about 2 months ago Actions #2 [ruby-core:127116]

Matz approved it.

Updated by jhawthorn (John Hawthorn) about 1 month ago Actions #3

  • Status changed from Open to Closed

Applied in changeset git|f609897fa4478f6116e6d30009e956c79ff7a186.


Add Ractor#alive?

Matches Thread#alive? and Fiber#alive?. Returns false once the ractor's
result has been recorded. Reads sync.legacy under the ractor lock, as
Ractor#monitor does, so it cannot race with termination.

[Feature #22441]

Actions

Also available in: PDF Atom