---
name: "mutex_trylock"
section: "9"
platform: "linux"
package: "linux-manual-4.9"
version: "4.9.228-1"
release: "Debian 9 (Stretch)"
platforms: ["linux"]
url: "https://new.carta.tech/mutex_trylock"
---

# mutex\_trylock(9)

try to acquire the mutex, without waiting

## NAME

mutex\_trylock - try to acquire the mutex, without waiting

## SYNOPSIS

**int \_\_sched mutex\_trylock(struct mutex \*** *lock***);**

## ARGUMENTS

*lock*

the mutex to be acquired

## DESCRIPTION

Try to acquire the mutex atomically. Returns 1 if the mutex has been acquired successfully, and 0 on contention.

## NOTE

this function follows the **spin\_trylock** convention, so it is negated from the **down\_trylock** return values! Be careful about this when converting semaphore users to mutexes.

This function must not be used in interrupt context. The mutex must be released by the same task that acquired it.

## AUTHOR

**Rusty Russell** \<rusty@rustcorp.com.au\>

Author.

## COPYRIGHT
