<!--
{
  "availability" : [
    "iOS: 10.0.0 -",
    "iPadOS: 10.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.12.0 -",
    "tvOS: 10.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 3.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "os",
  "identifier" : "/documentation/os/os_unfair_lock_trylock",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "os"
    ],
    "preciseIdentifier" : "c:@F@os_unfair_lock_trylock"
  },
  "title" : "os_unfair_lock_trylock"
}
-->

# os_unfair_lock_trylock

Locks an unfair lock if it is not already locked.

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

## Parameters

`lock`

A pointer to the unfair lock to be locked.

## Return Value

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

## Discussion

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

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)