---
title: os_unfair_lock_trylock
framework: os
role: symbol
role_heading: Function
path: os/os_unfair_lock_trylock
---

# os_unfair_lock_trylock

Locks an unfair lock if it is not already locked.

## Declaration

```occ
extern bool os_unfair_lock_trylock(os_unfair_lock_t lock);
```

## Parameters

- `lock`: A pointer to the unfair lock to be locked.

## Return Value

Return Value true if the lock was successfully locked, or false if the lock was already locked.

## Discussion

Discussion If this function returns false, you must either proceed without having acquired the lock or call os_unfair_lock_lock directly. Do not attempt to call this function within a retry loop; os_unfair_lock_lock accomplishes the same task, without hiding the lock waiter from the system or preventing resolution of priority inversions.

## See Also

### Unfair Locking

- [os_unfair_lock](os/os_unfair_lock.md)
- [OS_UNFAIR_LOCK_INIT](os/os_unfair_lock_init.md)
- [os_unfair_lock_t](os/os_unfair_lock_t.md)
- [os_unfair_lock_lock](os/os_unfair_lock_lock.md)
- [os_unfair_lock_lock_with_flags](os/os_unfair_lock_lock_with_flags.md)
- [os_unfair_lock_unlock](os/os_unfair_lock_unlock.md)
- [os_unfair_lock_assert_owner](os/os_unfair_lock_assert_owner.md)
- [os_unfair_lock_assert_not_owner](os/os_unfair_lock_assert_not_owner.md)
- [os_unfair_lock_flags_t](os/os_unfair_lock_flags_t.md)
