Title
How are two `seq_cst` operations ordered in the single total order if these two operations are unsequenced?
Status
new
Section
[atomics.order]
Submitter
jim x

Created on 2025-08-06.00:00:00 last changed 3 weeks ago

Messages

Date: 2025-08-09.15:53:17

Consider this snippet code:

std::atomic<int> flag = {0};
std::atomic<int> turn = {0};

if(flag + turn){}

The loads of `flag` and `turn` as the operands of `+` are unsequenced according to [intro.execution] p10.

Except where noted, evaluations of operands of individual operators and of subexpressions of individual expressions are unsequenced.

However, [atomics.order] p4 says:

There is a single total order S on all `memory_order::seq_cst` operations, including fences, that satisfies the following constraints.

Then, it says that:

First, if A and B are `memory_order::seq_cst` operations and A strongly happens before B, then A precedes B in S.

According to the first sentence, the load of `flag` and the load of `turn` do have an order in the single total order S since they are both `memory_order::seq_cst` operations. However, since they are unsequenced, the second sentence does not apply to them. So, what's the order of them in S? Is the order of them in S unspecified?

Suggested Resolution:

We may want to say the order of such operations is indeterminate in the single total order. That is, either A precedes B or B precedes A, but it is unspecified which.

History
Date User Action Args
2025-08-06 00:00:00admincreate