Join or detach of a joined or detached thread
Thread that was previously joined or detached is joined or detached again
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:
You try to join a thread that was previously joined or detached.
You try to detach a thread that was previously joined or detached.
The Result Details pane describes if the thread was previously joined or detached and also shows previous related events.
For instance, a thread joined with thrd_join
is then detached with
thrd_detach
:
thrd_t id; ... thrd_join(id, NULL); thrd_detach(id);
Note that a thread is considered as joined only if a previous thread joining is successful.
For instance, the thread is not considered as joined in the if
branch
here:
thrd_t t; ... if (thrd_success != thrd_join(t, 0)) { /* Thread not considered joined */ }
thrd_current()
function.Risk
The C11 standard (clauses 7.26.5.3 and 7.26.5.6) states that a thread shall not be joined or detached once it was previously joined or detached. Violating these clauses of the standard results in undefined behavior.
Fix
Avoid joining a thread that was already joined or detached previously. Avoid detaching a thread that was already joined or detached.
Examples
Result Information
Group: Concurrency |
Language: C |
Default: Off |
Command-Line Syntax:
DOUBLE_JOIN_OR_DETACH |
Impact: Medium |
Version History
Introduced in R2019b
See Also
Use of undefined thread
ID
| Missing or double initialization of
thread attribute
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)