---
name: "pthread_getspecific"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd", "macos"]
url: "https://new.carta.tech/pthread_getspecific"
---

# pthread\_getspecific(3)

get a thread-specific data value

## NAME

**pthread\_getspecific** – get a thread-specific data value

## LIBRARY

POSIX Threads Library (libpthread, -lpthread)

## SYNOPSIS

**#include \<pthread.h\>**

*void* *\**\

**pthread\_getspecific**(*pthread\_key\_t key*);

## DESCRIPTION

The **pthread\_getspecific**() function returns the value currently bound to the specified *key* on behalf of the calling thread.

The effect of calling **pthread\_getspecific**() with a *key* value not obtained from **pthread\_key\_create**() or after *key* has been deleted with **pthread\_key\_delete**() is undefined.

The **pthread\_getspecific**() function may be called from a thread-specific data destructor function. A call to **pthread\_getspecific**() for the thread-specific data key being destroyed returns the value NULL, unless the value is changed (after the destructor starts) by a call to **pthread\_setspecific**().

## RETURN VALUES

The **pthread\_getspecific**() function will return the thread-specific data value associated with the given *key*. If no thread-specific data value is associated with *key*, then the value NULL is returned.

## ERRORS

None.

## SEE ALSO

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

## STANDARDS

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