Knowledge baseExam Center
ENEnglish
Choose language13

CKTIS / C

cnd_destroy — C23 condition-variable function

`cnd_destroy(cond)` releases every resource used by a previously initialized condition variable and returns no value. C23 requires that no thread be blocked waiting on it when the call occurs.

Version: C23

Syntax

void cnd_destroy(cnd_t *cond);

cnd_destroy(cond) releases every resource used by a previously initialized condition variable and returns no value. C23 requires that no thread be blocked waiting on it when the call occurs.

The example first checks that cnd_init succeeded, then with zero waiters genuinely calls cnd_destroy and prints released 0, documenting the safe object-lifetime order.

Destroy only after every user has been awakened and joined; merely setting a predicate without joining does not prove that no waiter remains. After cnd_destroy, do not signal, wait on, or destroy that object again until another cnd_init succeeds.

Examples

#include <stdio.h>
#include <threads.h>

int main(void) {
    cnd_t condition;
    if (cnd_init(&condition) != thrd_success) return 1;
    int waiters = 0;
    cnd_destroy(&condition);
    printf("released %d\n", waiters);
    return 0;
}

Result

released 0

The example first checks that `cnd_init` succeeded, then with zero waiters genuinely calls `cnd_destroy` and prints `released 0`, documenting the safe object-lifetime order.

Sources