---
name: "pthread_mutex_trylock"
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_trylock"
---

# pthread\_mutex\_trylock(3)

attempt to lock a mutex without blocking

## NAME

**pthread\_mutex\_trylock** – attempt to lock a mutex without blocking

## LIBRARY

POSIX Threads Library (libpthread, -lpthread)

## SYNOPSIS

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

*int*\

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

## DESCRIPTION

The **pthread\_mutex\_trylock**() function locks *mutex*. If the mutex is already locked, **pthread\_mutex\_trylock**() will not block waiting for the mutex, but will return an error condition.

## RETURN VALUES

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

## ERRORS

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

- \[EINVAL\]

  The value specified by *mutex* is invalid.

- \[EBUSY\]

  *Mutex* is already locked.

- \[EOWNERDEAD\]

  The argument *mutex* points to a robust mutex and the process containing the previous owning thread terminated while holding the mutex lock. The lock was granted to the caller and it is up to the new owner to make the state consistent.

- \[ENOTRECOVERABLE\]

  The state protected by the *mutex* is not recoverable.

## SEE ALSO

[pthread\_mutex\_consistent(3)](/pthread_mutex_consistent/3.md), [pthread\_mutex\_destroy(3)](/pthread_mutex_destroy/3.md), [pthread\_mutex\_init(3)](/pthread_mutex_init/3.md), [pthread\_mutex\_lock(3)](/pthread_mutex_lock/3.md), [pthread\_mutex\_unlock(3)](/pthread_mutex_unlock/3.md)

## STANDARDS

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