---
name: "pthread_mutex_lock"
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_lock"
---

# pthread\_mutex\_lock(3)

lock a mutex

## NAME

**pthread\_mutex\_lock** – lock a mutex

## SYNOPSIS

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

*int*\

**pthread\_mutex\_lock**(*pthread\_mutex\_t \*mutex*);

## DESCRIPTION

The **pthread\_mutex\_lock**() function locks *mutex*. If the mutex is already locked, the calling thread will block until the mutex becomes available.

## RETURN VALUES

If successful, **pthread\_mutex\_lock**() will return zero, otherwise an error number will be returned to indicate the error.

## ERRORS

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

- \[EINVAL\]

  The value specified by *mutex* is invalid.

- \[EDEADLK\]

  A deadlock would occur if the thread blocked waiting for *mutex*.

## SEE ALSO

[pthread\_mutex\_destroy(3)](/pthread_mutex_destroy/3.md), [pthread\_mutex\_init(3)](/pthread_mutex_init/3.md), [pthread\_mutex\_trylock(3)](/pthread_mutex_trylock/3.md), [pthread\_mutex\_unlock(3)](/pthread_mutex_unlock/3.md)

## STANDARDS

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