<!--
{
  "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/DispatchSemaphore/init(value:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_semaphore_create"
  },
  "title" : "init(value:)"
}
-->

# init(value:)

Creates new counting semaphore with an initial value.

```
init(value: Int)
```

## Parameters

`value`

The starting value for the semaphore. Do not pass a value less than zero.

## Return Value

The newly created semaphore.

## Discussion

Passing zero for the value is useful for when two threads need to reconcile the completion of a particular event. Passing a value greater than zero is useful for managing a finite pool of resources, where the pool size is equal to the value.

> Important:
> Calls to ``doc://com.apple.dispatch/documentation/Dispatch/DispatchSemaphore/signal()`` must be balanced with calls to ``doc://com.apple.dispatch/documentation/Dispatch/DispatchSemaphore/wait()``. Attempting to dispose of a semaphore with a count lower than `value` causes an `EXC_BAD_INSTRUCTION` exception.

---

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)