<!--
{
  "availability" : [
    "iOS: 4.0.0 -",
    "iPadOS: 4.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.6.0 -",
    "tvOS: -",
    "visionOS: 1.0.0 -",
    "watchOS: 2.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/dispatch_semaphore_wait",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_semaphore_wait"
  },
  "title" : "dispatch_semaphore_wait"
}
-->

# dispatch_semaphore_wait

Waits for (decrements) a semaphore.

```
extern intptr_t dispatch_semaphore_wait(dispatch_semaphore_t dsema, dispatch_time_t timeout);
```

## Parameters

`dsema`

The semaphore. This parameter cannot be `NULL`.

`timeout`

When to timeout (see [`dispatch_time`](/documentation/Dispatch/dispatch_time)). The constants [`DISPATCH_TIME_NOW`](/documentation/Dispatch/DISPATCH_TIME_NOW) and [`DISPATCH_TIME_FOREVER`](/documentation/Dispatch/DISPATCH_TIME_FOREVER) are available as a convenience.

## Return Value

Returns zero on success, or non-zero if the timeout occurred.

## Discussion

Decrement the counting semaphore. If the resulting value is less than zero, this function waits for a signal to occur before returning.

---

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)