---
name: "pthread_key_delete"
section: "3"
platform: "macos"
package: "libpthread"
version: "539.100.4"
release: "macOS 26.5"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/pthread_key_delete"
---

# pthread\_key\_delete(3)

delete a thread-specific data key

## NAME

**pthread\_key\_delete** – delete a thread-specific data key

## SYNOPSIS

**#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

The **pthread\_key\_delete**() function will fail if:

- \[EINVAL\]

  The *key* value is invalid.

## SEE ALSO

[pthread\_getspecific(3)](/pthread_getspecific/3.md), [pthread\_key\_create(3)](/pthread_key_create/3.md), [pthread\_setspecific(3)](/pthread_setspecific/3.md)

## STANDARDS

The **pthread\_key\_delete**() function conforms to ISO/IEC 9945-1:1996 (“POSIX.1”).
