From: "ioquatix (Samuel Williams)" <noreply@ruby-lang.org>
To: ruby-core@ruby-lang.org
Subject: [ruby-core:106708] [Ruby master Bug#18411] Introduce `Fiber.blocking` for disabling scheduler.
Date: Thu, 16 Dec 2021 08:00:13 +0000 (UTC) [thread overview]
Message-ID: <redmine.journal-95393.20211216080013.3344@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-18411.20211216075858.3344@ruby-lang.org
Issue #18411 has been updated by ioquatix (Samuel Williams).
@matz this isn't strictly necessary but makes pure Ruby implementation of IO read/write hooks more efficient. I'm not sure if there is valid case for general user code. Can we consider it for Ruby 3.1?
----------------------------------------
Bug #18411: Introduce `Fiber.blocking` for disabling scheduler.
https://bugs.ruby-lang.org/issues/18411#change-95393
* Author: ioquatix (Samuel Williams)
* Status: Open
* Priority: Normal
* Backport: 2.6: UNKNOWN, 2.7: UNKNOWN, 3.0: UNKNOWN
----------------------------------------
When implementing pure-ruby IO scheduler, we may need to invoke some Ruby IO operations without entering the scheduler.
```ruby
def io_write(fiber, io, buffer, length)
offset = 0
while length > 0
# From offset until the end:
chunk = buffer.to_str(offset, length)
case result = io.write_nonblock(chunk, exception: false)
when :wait_readable
self.io_wait(fiber, io, IO::READABLE)
when :wait_writable
self.io_wait(fiber, io, IO::WRITABLE)
else
offset += result
length -= result
end
end
return offset
end
```
There are some cases where even in this code `read_nonblock` can invoke fiber scheduler creating infinite recursion.
Therefore, I propose to introduce `Fiber.blocking{...}` which has almost identical implementation to `Fiber.new(blocking: true) {}.resume`.
--
https://bugs.ruby-lang.org/
next prev parent reply other threads:[~2021-12-16 8:00 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-12-16 7:58 [ruby-core:106707] [Ruby master Bug#18411] Introduce `Fiber.blocking` for disabling scheduler ioquatix (Samuel Williams)
2021-12-16 8:00 ` ioquatix (Samuel Williams) [this message]
2022-09-21 7:12 ` [ruby-core:109971] [Ruby master Feature#18411] " ko1 (Koichi Sasada)
2022-09-21 10:51 ` [ruby-core:109975] " ioquatix (Samuel Williams)
2022-10-06 8:08 ` [ruby-core:110204] " ioquatix (Samuel Williams)
2022-10-08 7:34 ` [ruby-core:110235] " ioquatix (Samuel Williams)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-list from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: https://www.ruby-lang.org/en/community/mailing-lists/
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=redmine.journal-95393.20211216080013.3344@ruby-lang.org \
--to=ruby-core@ruby-lang.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).