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

# pthread\_join(3)

wait for thread termination

## NAME

**pthread\_join** – wait for thread termination

## SYNOPSIS

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

*int*\

**pthread\_join**(*pthread\_t thread*, *void \*\*value\_ptr*);

## DESCRIPTION

The **pthread\_join**() function suspends execution of the calling thread until the target *thread* terminates unless the target *thread* has already terminated.

On return from a successful **pthread\_join**() call with a non-NULL *value\_ptr* argument, the value passed to **pthread\_exit**() by the terminating thread is stored in the location referenced by *value\_ptr*. When a **pthread\_join**() returns successfully, the target thread has been terminated. The results of multiple simultaneous calls to **pthread\_join**() specifying the same target thread are undefined. If the thread calling **pthread\_join**() is cancelled, then the target thread is not detached.

## RETURN VALUES

If successful, the **pthread\_join**() function will return zero. Otherwise, an error number will be returned to indicate the error.

## ERRORS

The **pthread\_join**() function will fail if:

- \[EINVAL\]

  The implementation has detected that the value specified by *thread* does not refer to a joinable thread.

- \[ESRCH\]

  No thread could be found corresponding to that specified by the given thread ID, *thread*.

- \[EDEADLK\]

  A deadlock was detected or the value of *thread* specifies the calling thread.

## SEE ALSO

[wait(2)](/wait/2.md), [pthread\_create(3)](/pthread_create/3.md)

## STANDARDS

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