---
name: "pthread_mutex_init"
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_mutex_init"
---

# pthread\_mutex\_init(3)

create a mutex

## NAME

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

## LIBRARY

POSIX Threads Library (libpthread, -lpthread)

## SYNOPSIS

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

*int*\

**pthread\_mutex\_init**(*pthread\_mutex\_t \*restrict mutex*, *const pthread\_mutexattr\_t \*restrict 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”).
