Function that can spuriously fail not wrapped in loop
Loop checks failure condition after possible spurious failure
Description
This defect occurs when the following atomic compare and exchange functions that can fail spuriously are called from outside a loop.
C atomic functions:
atomic_compare_exchange_weak()
atomic_compare_exchange_weak_explicit()
C++ atomic functions:
std::atomic<T>::compare_exchange_weak(T* expected, T desired)
std::atomic<T>::compare_exchange_weak_explicit(T* expected, T desired, std::memory_order succ, std::memory_order fail)
std::atomic_compare_exchange_weak(std::atomic<T>* obj, T* expected, T desired)
std::atomic_compare_exchange_weak_explicit(volatile std::atomic<T>* obj, T* expected, T desired, std::memory_order succ, std::memory_order fail)
The functions compare the memory contents of the object representations pointed
to by obj
and expected
. The comparison can spuriously
return false even if the memory contents are equal. This spurious failure makes the functions
faster on some platforms.
Risk
An atomic compare and exchange function that spuriously fails can cause unexpected results and unexpected control flow.
Fix
Wrap atomic compare and exchange functions that can spuriously fail in a loop. The loop checks the failure condition after a possible spurious failure.
Examples
Result Information
Group: Concurrency |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
SPURIOUS_FAILURE_NOT_WRAPPED_IN_LOOP |
Impact: Low |
Version History
Introduced in R2018b
See Also
Function that can spuriously wake up not
wrapped in loop
| Returned value of a sensitive function not
checked
| 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)