Our website uses cookies to enhance your browsing experience.
Accept
to the top
>
>
>
V2670. MISRA. Thread objects, thread...
menu mobile close menu
Additional information
toggle menu Contents

V2670. MISRA. Thread objects, thread synchronization objects, and thread-specific storage pointers should only be accessed by the appropriate Standard Library functions.

Feb 05 2026

This diagnostic rule is based on the MISRA (Motor Industry Software Reliability Association) software development guidelines.

This diagnostic rule is relevant only for C.

Thread objects (thrd_t), mutexes (mtx_t), condition variables (cnd_t), and thread-specific storages (tss_t) should be accessed exclusively via special functions provided by the standard library:

Directly accessing struct members, as well as copying, modifying, or comparing them in any other way, leads to undefined behavior.

Look at the example:

thrd_t thread1, thread2;

int threads_equal(const thrd_t *t1, const thrd_t *t2)
{
  return memcmp(t1, t2, sizeof(thrd_t));
}

The memcmp function compares two thrd_t objects byte by byte. However, a developer may not know exactly how the control flow will be implemented in a particular standard C library. This can result in two identical threads being treated as different, for example, due to alignment bytes.

To properly compare objects of the thrd_t type and write portable code, use the thrd_equal function:

int threads_equal(const thrd_t *t1, const thrd_t *t2)
{
  return thrd_equal(t1, t2);
}

This diagnostic is classified as:

  • MISRA-C-2023-22.12