PTHREAD_KEY_DELETE(3) | Library Functions Manual | PTHREAD_KEY_DELETE(3)

# NAME

`pthread_key_delete` — delete a thread-specific data key

# SYNOPSIS

POSIX Threads Library (libpthread, -lpthread)
`#include <pthread.h>`

int
`pthread_key_delete`(pthread_key_t key);

# DESCRIPTION

The `pthread_key_delete`() function deletes a thread-specific data key previously returned by `pthread_key_create`(). The thread-specific data values associated with key need not be NULL at the time that `pthread_key_delete`() is called. It is the responsibility of the application to free any application storage or perform any cleanup actions for data structures related to the deleted key or associated thread-specific data in any threads; this cleanup can be done either before or after `pthread_key_delete`() is called. Any attempt to use key following the call to `pthread_key_delete`() results in undefined behavior.

The `pthread_key_delete`() function is callable from within destructor functions. Destructor functions are not invoked by `pthread_key_delete`(). Any destructor function that may have been associated with key will no longer be called upon thread exit.

# RETURN VALUES

If successful, the `pthread_key_delete`() function will return zero. Otherwise an error number will be returned to indicate the error.

# ERRORS

`pthread_key_delete`() will fail if:

[`EINVAL`]
  The key value is invalid.

# SEE ALSO

pthread_getspecific(3), pthread_key_create(3), pthread_setspecific(3)

# STANDARDS

`pthread_key_delete`() conforms to ISO/IEC 9945-1:1996 (“POSIX.1”).

June 7, 2025 | Debian