Use of undefined thread ID
Thread ID from failed thread creation used in subsequent thread functions
Description
This defect occurs when a thread creation
function such as pthread_create
fails but you continue to use the ID from
the thread creation.
For instance, pthread_join
uses an undefined thread ID after the
previous thread creation failed. The nonzero return value from
pthread_create
indicates the failed thread
creation.
pthread_t id; if(0! = pthread_create(&id, attr, start_func, NULL)) { ... phread_join(id, NULL); ... }
pthread_create
.Risk
According to the POSIX® standard, if thread creation fails, the contents of the thread ID are undefined. The use of an undefined thread ID can lead to unpredictable results.
The issue often indicates a programming error. For instance, it is possible that you tested for nonzero values to determine successful thread creation:
if(0 != pthread_create(&id, attr, start_func, NULL))
if(0 == pthread_create(&id, attr, start_func, NULL))
Fix
If the use of an undefined thread ID comes from a programming error, fix the error. Otherwise, remove the thread functions that are using the undefined ID.
Examples
Result Information
Group: Concurrency |
Language: C |
Default: Off |
Command-Line Syntax:
UNDEFINED_THREAD_ID |
Impact: Medium |
Version History
Introduced in R2019b
See Also
Missing or double initialization of
thread attribute
| Join or detach of a joined or detached
thread
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)