C++ Logo

std-discussion

Advanced search

Re: Is this program undefined-behavior or implementation-defined behavior?

From: Andrey Semashev <andrey.semashev_at_[hidden]>
Date: Tue, 13 Oct 2026 13:24:35 +0300
On 13 Oct 2026 11:43, jim x via Std-Discussion wrote:
> One of the grounds for your claim that the program exhibits undefined
> behavior is that you determined it contains a data race based on
> [intro.race] p17. But the very issue is: where does the standard state
> that an access to a volatile glvalue is non-atomic? The standard does
> not even define the semantics of such accesses and leaves them
> implementation-defined, making it even less possible to assert that
> accesses to a volatile glvalue are non-atomic. How, then, can you
> conclude based on [intro.race] that this program contains a data race?

You got it backwards. If the standard doesn't say volatile operations
are atomic then they are not. Or put it another way, you cannot rely on
them being atomic. Atomicity is not implied, the standard must
explicitly require an operation to be atomic for an implementation to
make an effort in making them atomic in the compiled program.

Received on 2026-10-13 10:24:40