CKTIS / C
mtx_destroy — release mutex resources
mtx_destroy from <threads.h> releases a mutex's resources. It returns no value; no thread may be blocked waiting for that mutex during destruction.
Version: C23; repository compiler flag, production runtime not attested
Syntax
#include <threads.h>
void mtx_destroy(mtx_t *mtx);mtx_destroy(mtx_t *mtx) releases resources used by the pointed-to mutex. It is declared in <threads.h> and returns void, not a success code.
The normative condition is that no thread may be blocked waiting for this mutex. A safe cleanup pattern is to finish using it, leave it unlocked, then call mtx_destroy. Do not treat destruction as a substitute for mtx_unlock.
The example destroys the mutex only after successful mtx_init. It creates no additional threads, so there are no waiters.
Examples
#include <stdio.h>
#include <stdlib.h>
#include <threads.h>
int main(void)
{
mtx_t mutex;
if (mtx_init(&mutex, mtx_plain) != thrd_success) {
return EXIT_FAILURE;
}
mtx_destroy(&mutex);
puts("Mutex destroyed.");
return EXIT_SUCCESS;
}
Result
Mutex destroyed.
The displayed code and declared result were verified in an isolated environment using the method recorded in the verification evidence for this exact version.