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

# DispatchQueue

An object that manages the execution of tasks serially or concurrently on your app’s main thread or on a background thread.

```
class DispatchQueue
```

## Overview

Dispatch queues are FIFO queues to which your application can submit tasks in the form of block objects. Dispatch queues execute tasks either serially or concurrently. Work submitted to dispatch queues executes on a pool of threads managed by the system. Except for the dispatch queue representing your app’s main thread, the system makes no guarantees about which thread it uses to execute a task.

You schedule work items synchronously or asynchronously. When you schedule a work item synchronously, your code waits until that item finishes execution. When you schedule a work item asynchronously, your code continues executing while the work item runs elsewhere.

> Important:
> Attempting to synchronously execute a work item on the main queue results in deadlock.

### Avoiding Excessive Thread Creation

When designing tasks for concurrent execution, do not call methods that block the current thread of execution. When a task scheduled by a concurrent dispatch queue blocks a thread, the system creates additional threads to run other queued concurrent tasks. If too many tasks block, the system may run out of threads for your app.

Another way that apps consume too many threads is by creating too many private concurrent dispatch queues. Because each dispatch queue consumes thread resources, creating additional concurrent dispatch queues exacerbates the thread consumption problem. Instead of creating private concurrent queues, submit tasks to one of the global concurrent dispatch queues. For serial tasks, set the target of your serial queue to one of the global concurrent queues. That way, you can maintain the serialized behavior of the queue while minimizing the number of separate queues creating threads.

## Topics

### Creating a Dispatch Queue

[`main`](/documentation/Dispatch/DispatchQueue/main)

The dispatch queue associated with the main thread of the current process.

[`global(qos:)`](/documentation/Dispatch/DispatchQueue/global(qos:))

Returns the global system queue with the specified quality-of-service class.

[`init(label:qos:attributes:autoreleaseFrequency:target:)`](/documentation/Dispatch/DispatchQueue/init(label:qos:attributes:autoreleaseFrequency:target:))

Creates a new dispatch queue to which you can submit blocks.

[`DispatchQoS.QoSClass`](/documentation/Dispatch/DispatchQoS/QoSClass-swift.enum)

Quality-of-service classes that specify the priorities for executing tasks.

[`DispatchQueue.Attributes`](/documentation/Dispatch/DispatchQueue/Attributes)

Attributes that define the behavior of a dispatch queue.

[`DispatchQueue.AutoreleaseFrequency`](/documentation/Dispatch/DispatchQueue/AutoreleaseFrequency)

Constants indicating the frequency with which a dispatch queue autoreleases objects.

[`OS_dispatch_queue_main`](/documentation/Dispatch/OS_dispatch_queue_main-swift.class)

A system-provided dispatch queue that schedules tasks for serial execution on the app’s main thread.

[`OS_dispatch_queue_global`](/documentation/Dispatch/OS_dispatch_queue_global-swift.class)

A system-provided dispatch queue that schedules tasks for concurrent execution.

[`DispatchSerialQueue`](/documentation/Dispatch/DispatchSerialQueue)

A custom dispatch queue that schedules tasks for serial execution on an arbitrary thread.

[`DispatchConcurrentQueue`](/documentation/Dispatch/DispatchConcurrentQueue)

A custom dispatch queue that schedules tasks for concurrent execution.

[`dispatch_queue_main_t`](/documentation/Dispatch/dispatch_queue_main_t)

A dispatch queue that is bound to the app’s main thread and executes tasks serially on that thread.

[`dispatch_queue_global_t`](/documentation/Dispatch/dispatch_queue_global_t)

A dispatch queue that executes tasks concurrently using threads from the global thread pool.

[`dispatch_queue_serial_t`](/documentation/Dispatch/dispatch_queue_serial_t)

A dispatch queue that executes tasks serially in first-in, first-out (FIFO) order.

[`dispatch_queue_concurrent_t`](/documentation/Dispatch/dispatch_queue_concurrent_t)

A dispatch queue that executes tasks concurrently and in any order, respecting any barriers that may be in place.

### Executing Tasks Asynchronously

[`async(execute:)`](/documentation/Dispatch/DispatchQueue/async(execute:))

Schedules a work item for immediate execution, and returns immediately.

[`asyncAfter(deadline:execute:)`](/documentation/Dispatch/DispatchQueue/asyncAfter(deadline:execute:))

Schedules a work item for execution at the specified time, and returns immediately.

[`asyncAfter(deadline:qos:flags:execute:)`](/documentation/Dispatch/DispatchQueue/asyncAfter(deadline:qos:flags:execute:))

Schedules a block for execution using the specified attributes, and returns immediately.

[`asyncAfter(wallDeadline:execute:)`](/documentation/Dispatch/DispatchQueue/asyncAfter(wallDeadline:execute:))

Schedules a work item for execution after the specified time, and returns immediately.

[`asyncAfter(wallDeadline:qos:flags:execute:)`](/documentation/Dispatch/DispatchQueue/asyncAfter(wallDeadline:qos:flags:execute:))

Schedules a block for execution using the specified attributes, and returns immediately.

### Executing Tasks Synchronously

[`sync(execute:)`](/documentation/Dispatch/DispatchQueue/sync(execute:)-2fzvo)

Submits a work item for execution on the current queue and returns after that block finishes executing.

[`sync(execute:)`](/documentation/Dispatch/DispatchQueue/sync(execute:)-3segw)

Submits a block object for execution and returns after that block finishes executing.

[`sync(execute:)`](/documentation/Dispatch/DispatchQueue/sync(execute:)-20xby)

Submits a work item for execution and returns the results from that item after it finishes executing.

[`sync(flags:execute:)`](/documentation/Dispatch/DispatchQueue/sync(flags:execute:))

Submits a work item for execution using the specified attributes and returns the results from that item after it finishes executing.

[`asyncAndWait(execute:)`](/documentation/Dispatch/DispatchQueue/asyncAndWait(execute:)-1udeu)

Submits a work item for execution and returns only after it finishes executing.

### Executing a Task in Parallel

[`concurrentPerform(iterations:execute:)`](/documentation/Dispatch/DispatchQueue/concurrentPerform(iterations:execute:))

Submits a single block to the dispatch queue and causes the block to be executed the specified number of times.

### Dispatching Work to Groups

[`async(group:execute:)`](/documentation/Dispatch/DispatchQueue/async(group:execute:))

Schedules a work item asynchronously for execution and associates it with the specified dispatch group.

[`async(group:qos:flags:execute:)`](/documentation/Dispatch/DispatchQueue/async(group:qos:flags:execute:))

Schedules a block asynchronously for execution and optionally associates it with a dispatch group.

### Managing Queue Attributes

[`label`](/documentation/Dispatch/DispatchQueue/label)

The label you assigned to the dispatch queue at creation time.

[`qos`](/documentation/Dispatch/DispatchQueue/qos)

The quality-of-service level assgined to the queue.

[`setTarget(queue:)`](/documentation/Dispatch/DispatchObject/setTarget(queue:))

Specifies the dispatch queue on which to perform work associated with the current object.

### Getting and Setting Contextual Data

[`setSpecific(key:value:)`](/documentation/Dispatch/DispatchQueue/setSpecific(key:value:))

Sets the key/value data for the specified dispatch queue.

[`getSpecific(key:)`](/documentation/Dispatch/DispatchQueue/getSpecific(key:)-swift.method)

Returns the value for the key associated with this dispatch queue.

[`getSpecific(key:)`](/documentation/Dispatch/DispatchQueue/getSpecific(key:)-swift.type.method)

Returns the value for the key associated with the current execution context.

[`DispatchSpecificKey`](/documentation/Dispatch/DispatchSpecificKey)

A key associated with a specific contextual value on a dispatch queue.

### Managing the Main Dispatch Queue

[`dispatchMain()`](/documentation/Dispatch/dispatchMain())

Executes blocks submitted to the main queue.

### Scheduling Combine Publishers

[`DispatchQueue.SchedulerTimeType`](/documentation/Dispatch/DispatchQueue/SchedulerTimeType)

The scheduler time type used by the dispatch queue.

[`DispatchQueue.SchedulerOptions`](/documentation/Dispatch/DispatchQueue/SchedulerOptions)

A set of options that affect the operation of the dispatch queue scheduler.

### Deprecated

[`global(priority:)`](/documentation/Dispatch/DispatchQueue/global(priority:))

[`DispatchQueue.GlobalQueuePriority`](/documentation/Dispatch/DispatchQueue/GlobalQueuePriority)

Legacy constants for queue priorities.



---

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)
