Atomic variable accessed twice in an expression
Variable can be modified between accesses
Description
This defect occurs
when C atomic types or C++
std::atomic
class variables appear twice in an expression and
there are:
Two atomic read operations on the variable.
An atomic read and a distinct atomic write operation on the variable.
The C standard defines certain operations on atomic variables that are thread safe and do not cause data race conditions. Unlike individual operations, a pair of operations on the same atomic variable in an expression is not thread safe.
Risk
A thread can modify the atomic variable between the pair of atomic operations, which can result in a data race condition.
Fix
Do not reference an atomic variable twice in the same expression.
Examples
Result Information
Group: Concurrency |
Language: C | C++ |
Default: On for handwritten code, off for generated code |
Command-Line Syntax:
ATOMIC_VAR_ACCESS_TWICE |
Impact: Medium |
Version History
Introduced in R2018b
See Also
Atomic load and store sequence not atomic
| Data race
| Find defects (-checkers)
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)