You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
For each function invocation or evaluation of an await-expression F, each evaluation that does not occur within F but is evaluated on the same thread and as part of the same signal handler (if any) is either sequenced before all evaluations that occur within F or sequenced after all evaluations that occur within F; if F invokes or resumes a coroutine ([expr.await]), only evaluations subsequent to the previous suspension (if any) and prior to the next suspension (if any) are considered to occur within F.
For invoking a coroutine(F is a coroutine call), the current wording seems to have no big problem. However, for co_await expression(IIUC, F refers to the co_await expression), It is a bit vague. I try to use the following illustration(not a c++ code) to expound on the problem I'm concerning. For concisely, ignore the suspension produced by initial-suspend and final suspend or they do not suspend a coroutine.
functionA(){
// just talk about the suspension produced by user-written co_await expression// as per [expr.await], evaluate a single co_await consists of: 1: o expression
2: r = await-ready
3: r == false then suspension // #14: await-suspend
break point // #25: await-resume
}
intmain(){
functionA();
// #3
evaluation B
resume functionA
evaluation C
}
Firstly, I don't know why we need to say F resumes a coroutine. Consider line 1,2,3,4,5 is a complete evaluation of a single co_await expression(if ignore the suspension), when evaluating this co_await expression, if r is false, then at that point, the coroutine is considered suspension, assume await-suspend is a prvalue of type void, the control flow will back to #3, which means in this perspective, the evaluation 1, 2, 3, 4 should be considered to occur within F since evaluation B will be evaluated, which means line 5 is not considered occur within F at this point, otherwise evaluation B cannot be evaluated until at least line 5 has been evaluated. In this example, F does not resume any coroutine.
Moreover, consider at the beginning of evaluating the co_await expression, #1 is the next suspension, however, the line 4 still needs to be evaluated but it is after the "next suspension" point, in other words, the line 4 should be considered to occur within F. The above rule does not fit here.
When we back to #2 by "resume functionA", line 5 is considered to occur within F since it is subsequent to the previous suspension #1, which means "evaluation C" is either before or after the line 5.
Instead, in terms of the current wording, does it permit that the evaluation B could be sequence after 1, 2, 3? Since for function(coroutine) invoke F and co_await F', only 1, 2, 3 are considered to occur within F and F'.
The text was updated successfully, but these errors were encountered:
[dcl.fct.def.coroutine] p8 explains how F might resume a coroutine.
Other than that, I understand that [expr.await] p5.1 says the coroutine is suspended, but then goes on and evaluates await-suspend, which has unclear sequencing.
jensmaurer
changed the title
[basic.exec.intro.execution] p11 sequence of co_await
[intro.execution] p11 sequencing of co_await
Sep 4, 2021
Yes, since CWG2466 claims that a co_await expression is a single evaluation but didn't give more clarifications. I think a co_await expression can result in suspension, which means we should clearly define which evaluations are considered to be within the evaluation of co_await expression at some point. Incidentally, a co_await can cause suspension even it does not resume any coroutine(i.e no invoking a resumption member function [dcl.fct.def.coroutine#8]), we should also give the phrase about the sequence for this case(instead of saying F resumes a coroutine)
[basic.exec.intro.execution] p11
For invoking a coroutine(F is a coroutine call), the current wording seems to have no big problem. However, for co_await expression(IIUC,
F
refers to the co_await expression), It is a bit vague. I try to use the following illustration(not a c++ code) to expound on the problem I'm concerning. For concisely, ignore the suspension produced by initial-suspend and final suspend or they do not suspend a coroutine.Firstly, I don't know why we need to say
F resumes a coroutine
. Consider line1,2,3,4,5
is a complete evaluation of a single co_await expression(if ignore the suspension), when evaluating this co_await expression, ifr
is false, then at that point, the coroutine is considered suspension, assumeawait-suspend
is a prvalue of type void, the control flow will back to#3
, which means in this perspective, the evaluation1, 2, 3, 4
should be considered to occur withinF
sinceevaluation B
will be evaluated, which means line5
is not considered occur withinF
at this point, otherwiseevaluation B
cannot be evaluated until at least line5
has been evaluated. In this example, F does not resume any coroutine.Moreover, consider at the beginning of evaluating the co_await expression,
#1
is the next suspension, however, the line4
still needs to be evaluated but it is after the "next suspension" point, in other words, the line4
should be considered to occur within F. The above rule does not fit here.When we back to
#2
by "resume functionA", line5
is considered to occur within F since it is subsequent to the previous suspension#1
, which means "evaluation C" is either before or after the line5
.Instead, in terms of the current wording, does it permit that the
evaluation B
could be sequence after1, 2, 3
? Since for function(coroutine) invoke F and co_awaitF'
, only1, 2, 3
are considered to occur withinF
andF'
.The text was updated successfully, but these errors were encountered: