Another developer has shown me the following snippet:
std::atomic_flag lock;
// ...
while (lock.test_and_set(std::memory_order::acquire)) {}
// critical section
lock.clear(std::memory_order::release);
I’m confused about what specifying acquire
as the memory order does here.
Is this implicitly the same order as acq_rel
, or is it acquire
for the load operation and seq_cst
(the default) for the store operation within this read-modify-write operation?
std::atomic_flag::test_and_set
has no preconditions and it is merely said that:
Memory is affected according to the value of
order
.
That doesn’t clarify things for me. What if order
is acquire
? How is the store affected then, huh?