<!--
{
  "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_source_create",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_source_create"
  },
  "title" : "dispatch_source_create"
}
-->

# dispatch_source_create

Creates a new dispatch source to monitor low-level system events.

## Parameters

`type`

The type of the dispatch source. For example, to create a timer source, specify [`DISPATCH_SOURCE_TYPE_TIMER`](/documentation/Dispatch/DISPATCH_SOURCE_TYPE_TIMER). For a complete list of constants, see [`dispatch_source_type_t`](/documentation/Dispatch/dispatch_source_type_t).

`handle`

The underlying system handle to monitor. The interpretation of this argument is determined by the constant provided in the type parameter.

`mask`

A mask of flags specifying which events are desired. The interpretation of this argument is determined by the constant provided in the type parameter.

`queue`

The dispatch queue to which the event handler block is submitted.

## Return Value

A new dispatch source object or `NULL` if the dispatch source could not be created.

## Discussion

Dispatch sources are not reentrant. Any events received while the dispatch source is suspended or while the event handler block is currently executing are coalesced and delivered after the dispatch source is resumed or the event handler block has returned.

Dispatch sources are created in a suspended state. After creating the source and setting any desired attributes (for example, the handler or the context), your application must call [`activate()`](/documentation/Dispatch/DispatchObject/activate()) to begin event delivery.

> Important:
> Event source creation is asynchronous, so be aware of any race conditions with monitored system handles. For example, if a dispatch source is created for a process and that process exits before the source is created, any specified cancellation handler may not be called.

---

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)
