MISRA C:2023 Rule 21.26
The Standard Library function mtx_timedlock() shall only be invoked on mutex objects of appropriate mutex type
Since R2025b
Description
Rule Definition
The Standard Library function mtx_timedlock() shall only be invoked on mutex objects of appropriate mutex type.1
Rationale
The function mtx_timedlock()
should only be used on mutexes that support a timeout functionality, specifically those initialized with the type mtx_timed
or mtx_timed | mtx_recursive
. Using mtx_timedlock()
on a mutex initialized with other types, such as mtx_plain
, results in undefined behavior.
For example, the following code results in undefined behavior:
mtx_t m;
mtx_init(&m, mtx_plain);
mtx_timedlock(&m, ts);
Polyspace Implementation
The rule checker reports a violation if a mutex of type mtx_t
used by mtx_timedlock()
was not previously initialized with type mtx_timed
or mtx_timed | mtx_recursive
.
Troubleshooting
If you expect a rule violation but Polyspace® does not report it, see Diagnose Why Coding Standard Violations Do Not Appear as Expected.
Examples
Check Information
Group: Standard libraries |
Category: Required |
AGC Category: Required |
Version History
Introduced in R2025b
1 All MISRA coding rules and directives are © Copyright The MISRA Consortium Limited 2021.
The MISRA coding standards referenced in the Polyspace Bug Finder™ documentation are from the following MISRA standards:
MISRA C:2004
MISRA C:2012
MISRA C:2023
MISRA C++:2008
MISRA C++:2023
MISRA and MISRA C are registered trademarks of The MISRA Consortium Limited 2021.