CKTIS / C
thrd_equal — comparing thread identity
The thrd_equal function from <threads.h> checks whether two thrd_t identifiers refer to the same thread. It returns zero or a nonzero value.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <threads.h>
int thrd_equal(thrd_t thr0, thrd_t thr1);thrd_equal(thr0, thr1) returns 0 for different threads and a nonzero value for the same thread. Do not assume that a true result is exactly 1.
Use this function rather than comparing identifiers with ==: the representation of thrd_t is implementation-defined. An identifier can be reused after its thread exits and is detached or joined.
The example compares the current thread's identifier with a freshly obtained identifier. The != 0 operator normalizes the result to 1. Support for <threads.h> is required; selecting C23 mode alone does not establish that support.
Examples
#include <stdio.h>
#include <threads.h>
int main(void)
{
thrd_t self = thrd_current();
int same = thrd_equal(self, thrd_current()) != 0;
printf("same thread: %d\n", same);
return 0;
}
Result
same thread: 1
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.