---
title: Dispatch Queue
framework: dispatch
role: collectionGroup
role_heading: API Collection
path: dispatch/dispatch-queue
---

# Dispatch Queue

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

## Overview

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. Dispatch queues provide minimal support for autoreleased objects by default. System APIs may return autoreleased objects to your code. For example, NSError objects are often autoreleased. If you see memory pressure increase because of autoreleased objects created in your blocks, consider adding autorelease pools to those blocks to relieve the pressure. You can also configure the default autorelease behavior of any custom dispatch queues using the dispatch_queue_attr_make_with_autorelease_frequency function at creation time. 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

- [dispatch_queue_t](dispatch/dispatch_queue_t.md)
- [dispatch_queue_main_t](dispatch/dispatch_queue_main_t.md)
- [dispatch_queue_global_t](dispatch/dispatch_queue_global_t.md)
- [dispatch_queue_serial_t](dispatch/dispatch_queue_serial_t.md)
- [dispatch_queue_concurrent_t](dispatch/dispatch_queue_concurrent_t.md)

### Configuring Queue Execution Parameters

- [dispatch_queue_attr_t](dispatch/dispatch_queue_attr_t.md)

### Executing Tasks Synchronously

- [sync(execute:)](dispatch/dispatchqueue/sync(execute:)-3segw.md)
- [asyncAndWait(execute:)](dispatch/dispatchqueue/asyncandwait(execute:)-1udeu.md)

### Managing Queue Attributes

- [setTarget(queue:)](dispatch/dispatchobject/settarget(queue:).md)

### Managing the Main Dispatch Queue

- [dispatchMain()](dispatch/dispatchmain().md)

## See Also

### Queues and Tasks

- [DispatchQueue](dispatch/dispatchqueue.md)
- [DispatchWorkItem](dispatch/dispatchworkitem.md)
- [DispatchGroup](dispatch/dispatchgroup.md)
- [Dispatch Work Item](dispatch/dispatch-work-item.md)
- [Dispatch Group](dispatch/dispatch-group.md)
- [Workloop](dispatch/workloop.md)
