Task performs lengthy operation while holding a lock
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 and
system
Functions for I/O operations such as getchar and
scanf
File handling functions such as fopen, remove
and lstat
Directory manipulation functions such as mkdir and
rmdir
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 the
documentation of Polyspace®
Bug Finder™ or Polyspace
Bug Finder
Server™.
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.
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.
| Group: Concurrency |
| Language: C | C++ |
| Default: Off |
Command-Line Syntax:
BLOCKING_WHILE_LOCKED |
| Impact: Low |
| CWE ID: 667 |