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

# pthread\_mutex\_init(3)

create a mutex

## NAME

**pthread\_mutex\_init** – create a mutex

## SYNOPSIS

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

*int*\

**pthread\_mutex\_init**(*pthread\_mutex\_t \*mutex*, *const pthread\_mutexattr\_t \*attr*);

## DESCRIPTION

The **pthread\_mutex\_init**() function creates a new mutex, with attributes specified with *attr*. If *attr* is NULL the default attributes are used.

## RETURN VALUES

If successful, **pthread\_mutex\_init**() will return zero and put the new mutex id into *mutex*, otherwise an error number will be returned to indicate the error.

## ERRORS

The **pthread\_mutex\_init**() function will fail if:

- \[EINVAL\]

  The value specified by *attr* is invalid.

- \[ENOMEM\]

  The process cannot allocate enough memory to create another mutex.

## SEE ALSO

[pthread\_mutex\_destroy(3)](/pthread_mutex_destroy/3.md), [pthread\_mutex\_lock(3)](/pthread_mutex_lock/3.md), [pthread\_mutex\_trylock(3)](/pthread_mutex_trylock/3.md), [pthread\_mutex\_unlock(3)](/pthread_mutex_unlock/3.md), [pthread\_mutexattr(3)](/pthread_mutexattr/3.md)

## STANDARDS

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