Created on 2026-10-21.00:00:00 last changed 2 weeks ago
Consider the following example:
#include <atomic>
#include <thread>
int main()
{
auto ptr = new std::atomic<int>{0};
auto t1 = std::jthread([&]() {
(*ptr).load(); // #1
});
auto t2 = std::jthread([&]() {
using Atomic = std::atomic<int>;
(*ptr).~Atomic(); // #2
});
}
Since neither `#1` happens-before nor happens-after `#2`, and `#1` is an atomic operation, whether this program contains a data race depends on whether `#2` is a non-atomic operation due to [intro.race] p17:
at least one of which is not an atomic operation
[atomics.types.operations] says:
Effects: Initializes the atomic object with the value of `T()`. Initialization is not an atomic operation ([intro.multithread]).
However, it lacks the wording to explicitly state that the destruction of an atomic object is not an atomic operation.
| History | |||
|---|---|---|---|
| Date | User | Action | Args |
| 2026-10-21 00:00:00 | admin | create | |