Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

The C Standard, 7.28.5.6 paragraph 2 [ISO/IEC 9899:2024], states that a thread shall not be joined once it was previously joined or detached.

The termination of the other thread synchronizes with the completion of the thrd_join function. The thread identified by thr shall not have been previously detached or joined with another thread.

Similarly, subclause 7.28.5.3 paragraph 2 [ISO/IEC 9899:2024], states that a thread shall not be detached once it was previously joined or detached. 

The thrd_detach function tells the operating system to dispose of any resources allocated to the thread identified by thr when that thread terminates. The thread identified by thr shall not have been previously detached or joined with another thread.

Violating either of these subclauses results in undefined behavior 211.

Noncompliant Code Example

...

Joining or detaching a previously joined or detached thread is undefined behavior 211.

Rule

Severity

Likelihood

Detectable

RepairableRemediation Cost

Priority

Level

CON39-C

Low

Likely

No

MediumNo

P6P3

L2L3

Automated Detection

Tool

Version

Checker

Description

Astrée
Include Page
Astrée_V
Astrée_V

Supported, but no explicit checker
CodeSonar
Include Page
CodeSonar_V
CodeSonar_V

CONCURRENCY.TNJ

Thread is not Joinable

Cppcheck Premium

Include Page
Cppcheck Premium_V
Cppcheck Premium_V

premium-cert-con39-cFully implemented
Helix QAC

Include Page
Helix QAC_V
Helix QAC_V

C1776
Parasoft C/C++test

Include Page
Parasoft_V
Parasoft_V

CERT_C-CON39-a

Do not join or detach a thread that was previously joined or detached

Polyspace Bug Finder

Include Page
Polyspace Bug Finder_V
Polyspace Bug Finder_V

CERT C: Rule CON39-CChecks for join or detach of a joined or detached thread (rule fully covered)

...