<!--
{
  "availability" : [
    "iOS: 18.0.0 -",
    "iPadOS: 18.0.0 -",
    "macCatalyst: -",
    "macOS: 15.0.0 -",
    "tvOS: 18.0.0 -",
    "visionOS: 2.0.0 -",
    "watchOS: 11.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "os",
  "identifier" : "/documentation/os/OSAllocatedUnfairLock/withLock(flags:_:)-1ub4c",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "os"
    ],
    "preciseIdentifier" : "s:2os21OSAllocatedUnfairLockV04withD05flags_qd__AA0bcD5FlagsV_qd__xzYbKXEtKs8SendableRd__lF"
  },
  "title" : "withLock(flags:_:)"
}
-->

# withLock(flags:_:)

```
func withLock<R>(flags: OSAllocatedUnfairLockFlags, _ body: @Sendable (inout State) throws -> R) rethrows -> R where R : Sendable
```

---

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)