Loop checks wake-up condition after possible spurious wake-up
This defect occurs when the following wait-on-condition functions are called from outside a loop:
C functions:
cnd_wait()
cnd_timedwait()
POSIX functions:
pthread_cond_wait()
pthread_cond_timedwait()
C++ std::condition_variable and
std::condition_variable_any class member functions:
wait()
wait_until()
wait_for()
Wait-on-condition functions pause the execution of the calling thread when a
specified condition is met. The thread wakes up and resumes once another thread notifies it
with cnd_broadcast() or an equivalent function. The wake-up notification
can be spurious or malicious.
If a thread receives a spurious wake-up notification and the condition of the wait-on-condition function is not checked, the thread can wake up prematurely. The wake-up can cause unexpected control flow, indefinite blocking of other threads, or denial of service.
Wrap wait-on-condition functions that can wake up spuriously in a loop. The loop checks the wake-up condition after a possible spurious wake-up notification.
| Group: Concurrency |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
SPURIOUS_WAKEUP_NOT_WRAPPED_IN_LOOP |
| Impact: Low |
Find defects (-checkers) | Function that can
spuriously fail not wrapped in loop | Returned value of a sensitive function not
checked