Atomic load and store sequence not atomic (ATOMIC_VAR_SEQUENCE_NOT_ATOMIC)
R2026bVariable accessible between load and store operations
Description
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.
Risk
A thread can modify a variable between the load and store operations, resulting in a data race condition.
Fix
To read, modify, and store a variable atomically, use a compound assignment operator
such as +=, atomic_compare_exchange() or
atomic_fetch_*-family functions.
Examples
Result Information
| Group: Concurrency |
| Language: C | C++ |
| Default: On for handwritten code, off for generated code |
Command-Line Syntax:
ATOMIC_VAR_SEQUENCE_NOT_ATOMIC
|
| Impact: Medium |
PQL Name:
std.defects.ATOMIC_VAR_SEQUENCE_NOT_ATOMIC
|
Version History
Introduced in R2018b
See Also
Atomic variable accessed twice in an expression | Data race | Find defects (-checkers)
Topics
- Interpret Polyspace Bug Finder Results in Polyspace Platform User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Polyspace Results Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)