---
title: "withLockIfAvailable(_:)"
framework: os
role: symbol
role_heading: Instance Method
path: "os/osallocatedunfairlock/withlockifavailable(_:)-1rp3w"
---

# withLockIfAvailable(_:)

## Declaration

```swift
func withLockIfAvailable<R>(_ body: @Sendable () throws -> R) rethrows -> R? where R : Sendable
```
