[#101174] [Ruby master Bug#17359] Ractor copy mode is not Ractor-safe — marcandre-ruby-core@...

Issue #17359 has been reported by marcandre (Marc-Andre Lafortune).

17 messages 2020/12/01

[#101217] [Ruby master Feature#17363] Timeouts — marcandre-ruby-core@...

Issue #17363 has been reported by marcandre (Marc-Andre Lafortune).

19 messages 2020/12/03

[#101250] [Ruby master Bug#17369] Introduce non-blocking `Process.wait`, `Kernel.system` and related methods. — samuel@...

Issue #17369 has been reported by ioquatix (Samuel Williams).

12 messages 2020/12/05

[#101276] [Ruby master Bug#17373] Ruby 3.0 is slower at Discourse bench than Ruby 2.7 — sam.saffron@...

Issue #17373 has been reported by sam.saffron (Sam Saffron).

11 messages 2020/12/07

[#101278] [Ruby master Bug#17374] Refined methods aren't visible from a refinementRefinements that include/prepend module — marcandre-ruby-core@...

Issue #17374 has been reported by marcandre (Marc-Andre Lafortune).

17 messages 2020/12/07

[#101317] [Ruby master Feature#17378] Ractor#receive with filtering like other actor langauge — ko1@...

Issue #17378 has been reported by ko1 (Koichi Sasada).

9 messages 2020/12/08

[#101343] [Ruby master Bug#17382] Segfault in String#inspect — lionel.perrin@...

Issue #17382 has been reported by lionelperrin (Lionel Perrin).

10 messages 2020/12/09

[#101381] [Ruby master Bug#17385] Test failures on gcc 11 — jaruga@...

Issue #17385 has been reported by jaruga (Jun Aruga).

18 messages 2020/12/10

[#101458] [Ruby master Bug#17394] TCPServer is not thread safe on win32 — aladjev.andrew@...

Issue #17394 has been reported by puchuu (Andrew Aladjev).

9 messages 2020/12/14

[#101472] [Ruby master Feature#17397] shareable_literal_constant should check at runtime, not at parse time — marcandre-ruby-core@...

Issue #17397 has been reported by marcandre (Marc-Andre Lafortune).

10 messages 2020/12/16

[#101475] [Ruby master Bug#17398] SyntaxError in endless method — zverok.offline@...

Issue #17398 has been reported by zverok (Victor Shepelev).

15 messages 2020/12/16

[#101477] [Ruby master Misc#17399] Are endless methods experimental? — zverok.offline@...

Issue #17399 has been reported by zverok (Victor Shepelev).

13 messages 2020/12/16

[#101480] [Ruby master Bug#17400] Incorrect character downcase for Greek Sigma — xfalcox@...

Issue #17400 has been reported by xfalcox (Rafael Silva).

10 messages 2020/12/16

[#101513] [Ruby master Bug#17405] irb ---nomultiline gets exception when output contains some non-ascii characters — rsharman@...

Issue #17405 has been reported by rsharman (Richard Sharman).

8 messages 2020/12/18

[#101534] [Ruby master Bug#17409] Endless range of dates stuck on include? when miss — sergey.gnuskov@...

Issue #17409 has been reported by gsmetal (Sergey G).

9 messages 2020/12/19

[#101546] [Ruby master Bug#17411] Syntax error with . in pattern — zverok.offline@...

Issue #17411 has been reported by zverok (Victor Shepelev).

10 messages 2020/12/19

[#101598] [Ruby master Bug#17420] Unsafe mutation of $" when doing non-RubyGems require in Ractor — eregontp@...

Issue #17420 has been reported by Eregon (Benoit Daloze).

12 messages 2020/12/21

[#101635] [Ruby master Bug#17428] Method#inspect bad output for class methods — marcandre-ruby-core@...

Issue #17428 has been reported by marcandre (Marc-Andre Lafortune).

13 messages 2020/12/23

[#101639] [Ruby master Bug#17429] Prohibit include/prepend in refinement modules — shugo@...

Issue #17429 has been reported by shugo (Shugo Maeda).

32 messages 2020/12/23

[#101707] [Ruby master Feature#17472] HashWithIndifferentAccess like Hash extension — naruse@...

Issue #17472 has been reported by naruse (Yui NARUSE).

31 messages 2020/12/26

[#101710] [Ruby master Feature#17473] Make Pathname to embedded class of Ruby — hsbt@...

Issue #17473 has been reported by hsbt (Hiroshi SHIBATA).

28 messages 2020/12/26

[#101719] [Ruby master Feature#17474] Interpreting constants at compile time — jzakiya@...

Issue #17474 has been reported by jzakiya (Jabari Zakiya).

23 messages 2020/12/26

[#101735] [Ruby master Misc#17480] DevelopersMeeting20210113Japan — mame@...

Issue #17480 has been reported by mame (Yusuke Endoh).

12 messages 2020/12/27

[#101790] [Ruby master Bug#17486] Build fails on darwin due to libtool being removed — dark.panda@...

Issue #17486 has been reported by dark.panda (J Smith).

11 messages 2020/12/28

[#101794] [Ruby master Bug#17488] Regression in Ruby 3: Hash#key? is non-deterministic when argument uses DelegateClass — myron.marston@...

Issue #17488 has been reported by myronmarston (Myron Marston).

11 messages 2020/12/28

[#101809] [Ruby master Feature#17490] Rename RubyVM::MJIT to RubyVM::JIT — takashikkbn@...

Issue #17490 has been reported by k0kubun (Takashi Kokubun).

15 messages 2020/12/30

[#101838] [Ruby master Feature#17496] Add constant Math::TAU — jzakiya@...

Issue #17496 has been reported by jzakiya (Jabari Zakiya).

32 messages 2020/12/31

[#101840] [Ruby master Bug#17497] Ractor performance issue — marcandre-ruby-core@...

Issue #17497 has been reported by marcandre (Marc-Andre Lafortune).

21 messages 2020/12/31

[ruby-core:101298] [Ruby master Feature#17375] Add scheduler callbacks for transferring fibers

From: nicholas.evans@...
Date: 2020-12-07 23:31:23 UTC
List: ruby-core #101298
Issue #17375 has been reported by nevans (Nicholas Evans).

----------------------------------------
Feature #17375: Add scheduler callbacks for transferring fibers
https://bugs.ruby-lang.org/issues/17375

* Author: nevans (Nicholas Evans)
* Status: Open
* Priority: Normal
----------------------------------------
When working on #17325 (`Fiber#cancel`) and #17331 (`Fiber#raise` on transferring fibers), two very reasonable questions keep coming up:
* "how and when should control pass back to the current fiber?" and
* "is it expected that terminating fibers will return to the root fiber chain?"

Rather than deal with that complexity, I've passed the buck: that's out of scope for those tickets. The end user should just call their scheduler library and let it coordinate, right?

But with a couple of optional hooks on the scheduler, I think we can answer both of those questions.  I'm not sure that these are the ideal API, but what do you think about *something* similar to the following?

### "how and when should control pass back to the current fiber?"

```ruby
# Called before transferring into another fiber.
# @param target [Fiber] the fiber that will be transferred into
# @param reason [:transfer, :raise, :cancel] How the transfer was initiated 
# @param args the arguments sent to transfer, raise, or cancel.
#
# @raise [FiberTransferInterrupted] to prevent the transfer without raising an
#     exception in the calling fiber.
# @raise [Exception] prevents the transfer and raises in the calling fiber
#
# This can be used to ensure the current fiber is appropriately scheduled for
# return, and it can also prevent the transfer or schedule the transfer to
# happen asynchronously.
#
# In addition to raising exceptions, any call to a fiber switching method (e.g.
# resume, yield, or transfer) will prevent the transfer. When a transfer is
# prevented, any associated cancellation or exception will not happen.
#
# This will only be called for transfers, not for resume, yield, or termination.
def transferring(target, reason, *args)
  # one possible implementation:
  return if Fiber.current == @scheduler # always allow transfer from scheduler
  if target == @scheduler
    # guard transfer to the scheduler
    raise FiberError, "invalid transfer to scheduler" if invalid?(reason, *args)
  else
    # schedule all transfers instead of running immediately
    @next_tick << [target, reason, *args]
    @next_tick << [Fiber.current, :transfer] unless blocking?
    @scheduler.transfer
  end
end
```

This would be useful for more than just `Fiber#raise` and `Fiber#cancel`. It could allows any non-scheduler code to safely call `Fiber#transfer` (or to indirectly transfer via `#raise` or `#cancel`) without confusing or breaking the scheduler. Or the scheduler could **disallow** any transfers but its own. Or it could intercept certain internal framework exceptions. It allows the scheduler some control over transfer and over raise/cancel with transferring fibers.

### "exceptions raised from terminating transferred fibers will return to the root fiber chain"

```ruby
# Select the return fiber for a transferring fiber when it terminates.
# @param terminating [Fiber] The terminating fiber
# @param retval [Object] return value of the terminating fiber
# @param error [Exception, nil] raised by terminating fiber
# @return [Fiber, nil] fiber to transfer into. `nil` uses default behavior
#
# If the selected return fiber can't be transferred to (because it is yielding
# or resuming or dead), FiberError will be raised on root fiber chain.
#
# This will be run in the terminating fiber after its block has completed.
# If this raises an exception, that will be raised on the root fiber chain.
#
def select_return_fiber(terminating, retval, error)
  supervisor = @supervised[terminating]
  if supervisor&.alive?
    supervisor
  elsif @scheduled.include?(terminating)
    @scheduler
  elsif !error
    raise FiberError, "unsupervised transfer fiber terminated"
  end
end
```

In addition to answering the question raised by #17325 and #17331, I think this also simplifies some other useful patterns, e.g. supervisors.

It would also let me easily fix one of the things that ruby 3.0 breaks in my current code: I liked to "init" my transfer fibers by first resuming into them from their supervisor and then immediately transferring back out. That sets the return_fiber for when it terminates. A workaround is to use an ensured `supervisor.transfer` on the last line of the fiber and then abandon the almost dead fiber. But that might lead to a bug later if some other code held onto a reference to that fiber, saw it was still alive, and transferred into it (unlikely, but plausible). And it's still brittle: if any errant code calls `Fiber.yield`, the return_fiber will be lost and can never be recovered. Letting the scheduler manage this would provide the lost ruby 2 functionality and more.

What do you think?



-- 
https://bugs.ruby-lang.org/

Unsubscribe: <mailto:ruby-core-request@ruby-lang.org?subject=unsubscribe>
<http://lists.ruby-lang.org/cgi-bin/mailman/options/ruby-core>

In This Thread

Prev Next