|
| 1 | +<?xml version='1.0' encoding='utf-8' standalone='no'?> |
| 2 | +<!DOCTYPE issue SYSTEM "lwg-issue.dtd"> |
| 3 | + |
| 4 | +<issue num="4150" status="New"> |
| 5 | +<title>The preconditions on <tt>run_loop::run()</tt> are too strict</title> |
| 6 | +<section><sref ref="[exec.run.loop.members]"/></section> |
| 7 | +<submitter>Eric Niebler</submitter> |
| 8 | +<date>05 Sep 2024</date> |
| 9 | +<priority>99</priority> |
| 10 | + |
| 11 | +<discussion> |
| 12 | +<p> |
| 13 | +From <a href="https://github.com/cplusplus/sender-receiver/issues/280">sender-receiver/issues #280</a>: |
| 14 | +<p/> |
| 15 | +The precondition on <tt>run_loop::run()</tt> is that the <tt><i>state</i></tt> is <i>starting</i>. |
| 16 | +Given that <tt>run_loop::finish()</tt> puts the loop in the <i>finishing</i> state, the implication |
| 17 | +is that one cannot call <tt>finish()</tt> before calling <tt>run()</tt>. |
| 18 | +<p/> |
| 19 | +However, in most cases <tt>sync_wait</tt> is calling <tt>finish()</tt> on its <tt>run_loop</tt> |
| 20 | +before calling run<tt>()</tt>, violating this precondition. <tt>sync_wait</tt> does the following: |
| 21 | +</p> |
| 22 | +<blockquote><pre> |
| 23 | +run_loop loop; |
| 24 | +auto op = connect(sndr, sync_wait_receiver{&loop}); |
| 25 | +start(op); |
| 26 | + |
| 27 | +loop.run(); |
| 28 | +</pre></blockquote> |
| 29 | +<p> |
| 30 | +If <tt>sndr</tt> completes synchronously, the <tt>sync_wait_receiver</tt> will call <tt>finish()</tt> |
| 31 | +on the loop before <tt>loop.run()</tt> is called, violating <tt>run</tt>'s precondition. |
| 32 | +</p> |
| 33 | +</discussion> |
| 34 | + |
| 35 | +<resolution> |
| 36 | +<p> |
| 37 | +This wording is relative to <paper num="N4988"/>. |
| 38 | +</p> |
| 39 | + |
| 40 | +<ol> |
| 41 | +<li><p>Modify <sref ref="[exec.run.loop.members]"/> as indicated:</p> |
| 42 | + |
| 43 | +<blockquote><pre> |
| 44 | +void run(); |
| 45 | +</pre> |
| 46 | +<blockquote> |
| 47 | +<p> |
| 48 | +-5- <i>Preconditions</i>: <tt><i>state</i></tt> is <i>starting</i> <ins>or <i>finishing</i></ins>. |
| 49 | +<p/> |
| 50 | +-6- <i>Effects</i>: Sets the <tt><i>state</i></tt> to <i>running</i>. Then, equivalent to: |
| 51 | +</p> |
| 52 | +<blockquote><pre> |
| 53 | +while (auto* op = pop-front ()) { |
| 54 | + op->execute (); |
| 55 | +} |
| 56 | +</pre></blockquote> |
| 57 | +<p> |
| 58 | +-7- <i>Remarks</i>: When <tt><i>state</i></tt> changes, it does so without introducing data races. |
| 59 | +</p> |
| 60 | +</blockquote> |
| 61 | +</blockquote> |
| 62 | +</li> |
| 63 | + |
| 64 | +</ol> |
| 65 | + |
| 66 | +</resolution> |
| 67 | + |
| 68 | +</issue> |
0 commit comments