---
title: dispatch_semaphore_wait
framework: dispatch
role: symbol
role_heading: Function
path: dispatch/dispatch_semaphore_wait
---

# dispatch_semaphore_wait

Waits for (decrements) a semaphore.

## Declaration

```occ
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 doc://com.apple.dispatch/documentation/Dispatch/dispatch_time). The constants doc://com.apple.dispatch/documentation/Dispatch/DISPATCH_TIME_NOW and doc://com.apple.dispatch/documentation/Dispatch/DISPATCH_TIME_FOREVER are available as a convenience.

## Return Value

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

## Discussion

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