CKTIS / C
thrd_exit — terminate the calling thread
thrd_exit terminates the calling thread and sets its int result, which can be retrieved using thrd_join.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <threads.h>
[[noreturn]] void thrd_exit(int res);thrd_exit(res) from <threads.h> terminates the calling thread without returning. Its argument res is the thread result, not the process exit status; thrd_join retrieves it. [[noreturn]] indicates that execution does not return.
Applicable thread-specific storage destructors run before termination, in an unspecified order. This does not replace explicit cleanup of other resources. Unlike exit, this function does not immediately terminate the entire program. Under N3096, termination of the last thread ends the program as if by exit(EXIT_SUCCESS).
Examples
#include <stdio.h>
#include <stdlib.h>
#include <threads.h>
static int worker(void *arg)
{
(void)arg;
thrd_exit(42);
}
int main(void)
{
thrd_t thread;
int result;
if (thrd_create(&thread, worker, NULL) != thrd_success) {
return EXIT_FAILURE;
}
if (thrd_join(thread, &result) != thrd_success) {
return EXIT_FAILURE;
}
printf("result = %d\n", result);
return EXIT_SUCCESS;
}Result
result = 42
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.