Blocking operation while holding lock
Task performs lengthy operation while holding a lock
Description
This checker is deactivated in a default Polyspace® as You Code analysis. See Checkers Deactivated in Polyspace as You Code Analysis (Polyspace Access).
This defect occurs when a task (thread) performs a potentially lengthy operation while holding a lock.
The checker considers calls to these functions as potentially lengthy:
Functions that access a network such as
recv
System call functions such as
fork
,pipe
andsystem
Functions for I/O operations such as
getchar
andscanf
File handling functions such as
fopen
,remove
andlstat
Directory manipulation functions such as
mkdir
andrmdir
The checker automatically detects certain primitives that hold and release a lock, for
instance, pthread_mutex_lock
and pthread_mutex_unlock
.
For the full list of primitives that are automatically detected, see Auto-Detection of Thread Creation and Critical Section in Polyspace.
Risk
If a thread performs a lengthy operation when holding a lock, other threads that use the lock have to wait for the lock to be available. As a result, system performance can slow down or deadlocks can occur.
Fix
Perform the blocking operation before holding the lock or after releasing the lock.
Some functions detected by this checker can be called in a way that does not make them
potentially lengthy. For instance, the function recv
can be called with
the parameter O_NONBLOCK
which causes the call to fail if no message is
available. When called with this parameter, recv
does not wait for a
message to become available.
Examples
Result Information
Group: Concurrency |
Language: C | C++ |
Default: Off |
Command-Line Syntax:
BLOCKING_WHILE_LOCKED |
Impact: Low |
Version History
Introduced in R2018b
See Also
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)