Date: Thu, 2 Sep 2021 21:24:22 -0400
I have a question about the new atomic do statement from P2066R8. What
happens if a user attempts to combine this with a do-while loop? Suppose
someone wrote code like the following:
extern int i; // Starts off equal to 0
void f() {
atomic do {
++i;
} while (i < 10);
}
I have 2 questions. Would this code compile, and if so what would it do?
I think it would be the same as an atomic do followed by an empty while
loop, and thus result in an infinite loop. It might be a good idea to
change the atomic do statement to require a semicolon after the closing
bracket, the way a semicolon is required at the end of a regular
do-while loop.
Joe Gottman
happens if a user attempts to combine this with a do-while loop? Suppose
someone wrote code like the following:
extern int i; // Starts off equal to 0
void f() {
atomic do {
++i;
} while (i < 10);
}
I have 2 questions. Would this code compile, and if so what would it do?
I think it would be the same as an atomic do followed by an empty while
loop, and thus result in an infinite loop. It might be a good idea to
change the atomic do statement to require a semicolon after the closing
bracket, the way a semicolon is required at the end of a regular
do-while loop.
Joe Gottman
Received on 2021-09-02 20:24:27