Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[intro.execution] p11 sequencing of co_await #4861

Open
xmh0511 opened this issue Sep 3, 2021 · 3 comments
Open

[intro.execution] p11 sequencing of co_await #4861

xmh0511 opened this issue Sep 3, 2021 · 3 comments

Comments

@xmh0511
Copy link
Contributor

xmh0511 commented Sep 3, 2021

[basic.exec.intro.execution] p11

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  // #1
   4: await-suspend 
        break point   // #2
   5: await-resume
}
int main(){
   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'.

@jensmaurer
Copy link
Member

[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 jensmaurer changed the title [basic.exec.intro.execution] p11 sequence of co_await [intro.execution] p11 sequencing of co_await Sep 4, 2021
@jensmaurer
Copy link
Member

@xmh0511
Copy link
Contributor Author

xmh0511 commented 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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants