Variable accessible between load and store operations
This defect occurs when you use these functions to load, and then store an atomic variable.
C functions:
atomic_load()
atomic_load_explicit()
atomic_store()
atomic_store_explicit()
C++ functions:
std::atomic_load()
std::atomic_load_explicit()
std::atomic_store()
std::atomic_store_explicit()
std::atomic::load()
std::atomic::store()
A thread cannot interrupt an atomic load or an atomic store operation on a variable, but a thread can interrupt a store, and then load sequence.
A thread can modify a variable between the load and store operations, resulting in a data race condition.
To read, modify, and store a variable atomically, use a compound assignment operator
such as +=, atomic_compare_exchange() or
atomic_fetch_*-family functions.
| Group: Concurrency |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
ATOMIC_VAR_SEQUENCE_NOT_ATOMIC |
| Impact: Medium |
Atomic variable accessed
twice in an expression | Data race | Data race including atomic operations | Find defects (-checkers)