https://redmine.ruby-lang.org/https://redmine.ruby-lang.org/favicon.ico?17113305112020-10-07T17:35:11ZRuby Issue Tracking SystemRuby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879092020-10-07T17:35:11Zko1 (Koichi Sasada)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/87909/diff?detail_id=58087">diff</a>)</li></ul> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879142020-10-07T17:57:52Zko1 (Koichi Sasada)
<ul><li><strong>File</strong> <i>clipboard-202010080248-9wdyk.png</i> added</li><li><strong>File</strong> <a href="/attachments/8564">clipboard-202010080257-u2lbv.png</a> <a class="icon-only icon-download" title="Download" href="/attachments/download/8564/clipboard-202010080257-u2lbv.png">clipboard-202010080257-u2lbv.png</a> added</li></ul><a name="Implementation-note"></a>
<h2 >Implementation note<a href="#Implementation-note" class="wiki-anchor">¶</a></h2>
<p>Each fiber has "resuming_fiber" and we can check (1).</p>
<p><img src="https://redmine.ruby-lang.org/attachments/download/8564/clipboard-202010080257-u2lbv.png" alt="" loading="lazy"></p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879152020-10-07T18:07:43Zko1 (Koichi Sasada)
<ul><li><strong>File</strong> deleted (<del><i>clipboard-202010080248-9wdyk.png</i></del>)</li></ul> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879502020-10-07T20:03:20ZEregon (Benoit Daloze)
<ul></ul><p>This sounds great to me!</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879512020-10-07T22:31:46Zioquatix (Samuel Williams)samuel@oriontransfer.net
<ul></ul><p>Great work everyone!</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879522020-10-07T23:46:58Zko1 (Koichi Sasada)
<ul></ul><p>Note for (2). It can break compatibility, but transferred fibers can not be resumed more, so maybe nobody rely on mixing them.</p>
<pre><code class="ruby syntaxhl" data-language="ruby"><span class="nb">require</span> <span class="s1">'fiber'</span>
<span class="n">f</span> <span class="o">=</span> <span class="no">Fiber</span><span class="p">.</span><span class="nf">new</span> <span class="k">do</span>
<span class="kp">loop</span> <span class="k">do</span>
<span class="no">Fiber</span><span class="p">.</span><span class="nf">yield</span> <span class="ss">:ok</span>
<span class="k">end</span>
<span class="k">end</span>
<span class="nb">p</span> <span class="n">f</span><span class="p">.</span><span class="nf">resume</span>
<span class="nb">p</span> <span class="n">f</span><span class="p">.</span><span class="nf">transfer</span> <span class="c1">#=> 3.0 `transfer': attempt to transfer to an yielding fiber (FiberError)</span>
<span class="nb">p</span> <span class="n">f</span><span class="p">.</span><span class="nf">resume</span> <span class="c1">#=> 2.7 `resume': cannot resume transferred Fiber (FiberError)</span>
</code></pre> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879532020-10-08T00:48:10Zko1 (Koichi Sasada)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/87953/diff?detail_id=58127">diff</a>)</li></ul><p>I found "(4) can not yield from not-resumed fiber", so I updated the proposal body with (4).</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879552020-10-08T09:34:02ZEregon (Benoit Daloze)
<ul></ul><p>For (2), can we use the error message <code>attempt to transfer to a yielding fiber (FiberError)</code> (yielding instead of resuming)? That seems clearer since f2 is not resuming but waiting for a <code>resume</code> and inside <code>Fiber.yield</code> (= yielding).</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879632020-10-09T19:18:40Zko1 (Koichi Sasada)
<ul><li><strong>Description</strong> updated (<a title="View differences" href="/journals/87963/diff?detail_id=58135">diff</a>)</li></ul><p>Eregon (Benoit Daloze) wrote in <a href="#note-8">#note-8</a>:</p>
<blockquote>
<p>For (2), can we use the error message <code>attempt to transfer to a yielding fiber (FiberError)</code> (yielding instead of resuming)? That seems clearer since f2 is not resuming but waiting for a <code>resume</code> and inside <code>Fiber.yield</code> (= yielding).</p>
</blockquote>
<p>It was my mistake. Implementation says</p>
<blockquote>
<p>`transfer': attempt to transfer to an yielding fiber (FiberError)</p>
</blockquote>
<p>Description is updated.</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879642020-10-09T19:19:26Zko1 (Koichi Sasada)
<ul></ul><p>BTW, "a yielding"? "an yielding"?</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879652020-10-09T20:53:41ZEregon (Benoit Daloze)
<ul></ul><p>I believe it's <code>a yielding Fiber</code> (the first sound in yield-ing is not a vowel sound)</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879752020-10-11T03:13:12Zduerst (Martin Dürst)duerst@it.aoyama.ac.jp
<ul></ul><p>Eregon (Benoit Daloze) wrote in <a href="#note-11">#note-11</a>:</p>
<blockquote>
<p>I believe it's <code>a yielding Fiber</code> (the first sound in yield-ing is not a vowel sound)</p>
</blockquote>
<p>A Yes indeed for this question. (not an yes :-)</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879872020-10-12T00:16:51Zko1 (Koichi Sasada)
<ul></ul><p>Thanks!</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879882020-10-12T00:20:46Zko1 (Koichi Sasada)
<ul></ul><p>Next English question :)</p>
<p>"attempt to transfer to a yielding fiber" or "attempt to transfer to the yielding fiber" (a/the) on error message (error message when calling <code>fib.transfer</code> and <code>fib</code> is yielding).</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=879972020-10-12T09:31:34Zko1 (Koichi Sasada)
<ul></ul><p>BTW I already got Matz's approval so I'll merge it as soon as possible.</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=880002020-10-12T13:58:56Zko1 (Koichi Sasada)
<ul><li><strong>Status</strong> changed from <i>Open</i> to <i>Closed</i></li></ul><p>Applied in changeset <a class="changeset" title="relax Fiber#transfer's restriction Using Fiber#transfer with Fiber#resume for a same Fiber is li..." href="https://redmine.ruby-lang.org/projects/ruby-master/repository/git/revisions/bf3b2a43741e4f72be21bc6acf24d37e7fcff61c">git|bf3b2a43741e4f72be21bc6acf24d37e7fcff61c</a>.</p>
<hr>
<p>relax Fiber#transfer's restriction</p>
<p>Using Fiber#transfer with Fiber#resume for a same Fiber is<br>
limited (once Fiber#transfer is called for a fiber, the fiber<br>
can not be resumed more). This restriction was introduced to<br>
protect the resume/yield chain, but we realized that it is too much<br>
to protect the chain. Instead of the current restriction, we<br>
introduce some other protections.</p>
<p>(1) can not transfer to the resuming fiber.<br>
(2) can not transfer to the yielding fiber.<br>
(3) can not resume transferred fiber.<br>
(4) can not yield from not-resumed fiber.</p>
<p>[Bug <a class="issue tracker-1 status-5 priority-4 priority-default closed" title="Bug: Relax the Fiber#transfer's limitation (Closed)" href="https://redmine.ruby-lang.org/issues/17221">#17221</a>]</p>
<p>Also at the end of a transferred fiber, it had continued on root fiber.<br>
However, if the root fiber resumed a fiber (and that fiber can resumed<br>
another fiber), this behavior also breaks the resume/yield chain.<br>
So at the end of a transferred fiber, switch to the edge of resume<br>
chain from root fiber.<br>
For example, root fiber resumed f1 and f1 resumed f2, transferred to<br>
f3 and f3 terminated, then continue from the fiber f2 (it was continued<br>
from root fiber without this patch).</p> Ruby master - Bug #17221: Relax the Fiber#transfer's limitationhttps://redmine.ruby-lang.org/issues/17221?journal_id=880012020-10-12T16:16:39Zshan (Shannon Skipper)
<ul></ul><p>It seems like both "a" and "the" work here. I might say, "cannot transfer to a yielding Fiber" or "attempted transfer to a yielding Fiber."</p>