
<!--
{
  "availability" : [
    "iOS: -",
    "iPadOS: -",
    "macCatalyst: -",
    "macOS: -",
    "tvOS: -",
    "visionOS: -",
    "watchOS: -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/DispatchSemaphore",
  "metadataVersion" : "0.1.0",
  "role" : "Class",
  "symbol" : {
    "kind" : "Class",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:objc(cs)OS_dispatch_semaphore"
  },
  "title" : "DispatchSemaphore"
}
-->

# DispatchSemaphore

An object that controls access to a resource across multiple execution contexts through use of a traditional counting semaphore.

```
class DispatchSemaphore
```

## Overview

A dispatch semaphore is an efficient implementation of a traditional counting semaphore. Dispatch semaphores call down to the kernel only when the calling thread needs to be blocked. If the calling semaphore does not need to block, no kernel call is made.

You increment a semaphore count by calling the [`signal()`](/documentation/Dispatch/DispatchSemaphore/signal()) method, and decrement a semaphore count by calling [`wait()`](/documentation/Dispatch/DispatchSemaphore/wait()) or one of its variants that specifies a timeout.

## Topics

### Creating a Semaphore

[`init(value:)`](/documentation/Dispatch/DispatchSemaphore/init(value:))

Creates new counting semaphore with an initial value.

### Signaling the Semaphore

[`signal()`](/documentation/Dispatch/DispatchSemaphore/signal())

Signals (increments) a semaphore.

### Blocking on the Semaphore

[`wait()`](/documentation/Dispatch/DispatchSemaphore/wait())

Waits for, or decrements, a semaphore.

[`wait(timeout:)`](/documentation/Dispatch/DispatchSemaphore/wait(timeout:))

Waits for, or decrements, a semaphore.

[`wait(wallTimeout:)`](/documentation/Dispatch/DispatchSemaphore/wait(wallTimeout:))

Waits for, or decrements, a semaphore.



---

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)
