Loop checks failure condition after possible spurious failure
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.
An atomic compare and exchange function that spuriously fails can cause unexpected results and unexpected control flow.
Wrap atomic compare and exchange functions that can spuriously fail in a loop. The loop checks the failure condition after a possible spurious failure.
| Group: Concurrency |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
SPURIOUS_FAILURE_NOT_WRAPPED_IN_LOOP |
| Impact: Low |
Find defects (-checkers) | Function that can spuriously wake up not
wrapped in loop | Returned value of a sensitive function not
checked