<!--
{
  "documentType" : "article",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/workloop",
  "metadataVersion" : "0.1.0",
  "role" : "collectionGroup",
  "title" : "Workloop"
}
-->

# Workloop

A dispatch object that prioritizes the execution of tasks based on their quality-of-service (QoS) level.

## Discussion

A workloop is a priority-ordered dispatch queue that uses QoS levels to determine the execution order of tasks. Before it starts executing each new task, the queue evaluates the QoS levels of currently enqueued tasks and selects the one with the highest priority. Tasks with the QoS level `QOS_CLASS_USER_INTERACTIVE` have the highest priority, followed by tasks with the `QOS_CLASS_USER_INITIATED` priority, and so on.

A workloop is a type of [`dispatch_queue_t`](/documentation/Dispatch/dispatch_queue_t) object, and you use the same functions to enqueue new tasks. For example, use the [`dispatch_async`](/documentation/Dispatch/dispatch_async) function to enqueue a task asynchronously.

## Topics

### Creating a Dispatch Workloop

[`extern dispatch_workloop_tdispatch_workloop_create(const char *label);`](/documentation/Dispatch/dispatch_workloop_create)

Creates a new workloop with the specified label.

[`extern dispatch_workloop_tdispatch_workloop_create_inactive(const char *label);`](/documentation/Dispatch/dispatch_workloop_create_inactive)

Creates a new inactive workloop with the specified label.

[`typealias dispatch_workloop_t`](/documentation/Dispatch/dispatch_workloop_t)

A dispatch queue that prioritizes the execution of tasks based on their quality-of-service level.

[`@protocol OS_dispatch_workloop <OS_dispatch_queue>`](/documentation/Dispatch/OS_dispatch_workloop)

A dispatch queue that prioritizes the execution of tasks based on their quality-of-service level.

### Configuring the Workloop Behavior

[`extern void dispatch_workloop_set_autorelease_frequency(dispatch_workloop_t workloop, dispatch_autorelease_frequency_t frequency);`](/documentation/Dispatch/dispatch_workloop_set_autorelease_frequency)

Configures how the workloop manages the autorelease pools for the blocks it executes.

[`extern void dispatch_set_qos_class_floor(dispatch_object_t object, dispatch_qos_class_t qos_class, int relative_priority);`](/documentation/Dispatch/dispatch_set_qos_class_floor)

Specifies the minimum quality-of-service level for a dispatch queue, source, or workloop.

[`extern dispatch_qos_class_t dispatch_queue_get_qos_class(dispatch_queue_t queue, int *relative_priority_ptr);`](/documentation/Dispatch/dispatch_queue_get_qos_class)

Returns the quality-of-service class for the specified queue.

### Executing Tasks Asynchronously

[`extern void dispatch_async(dispatch_queue_t queue, dispatch_block_t block);`](/documentation/Dispatch/dispatch_async)

Submits a block for asynchronous execution on a dispatch queue and returns immediately.

[`extern void dispatch_async_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_async_f)

Submits an app-defined function for asynchronous execution on a dispatch queue and returns immediately.

[`extern void dispatch_after(dispatch_time_t when, dispatch_queue_t queue, dispatch_block_t block);`](/documentation/Dispatch/dispatch_after)

Enqueues a block for execution at the specified time.

[`extern void dispatch_after_f(dispatch_time_t when, dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_after_f)

Enqueues an app-defined function for execution at the specified time.

[`extern void dispatch_barrier_async(dispatch_queue_t queue, dispatch_block_t block);`](/documentation/Dispatch/dispatch_barrier_async)

Submits a barrier block for asynchronous execution and returns immediately.

[`extern void dispatch_barrier_async_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_barrier_async_f)

Submits a barrier function for asynchronous execution and returns immediately.

### Executing Tasks Synchronously

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

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

[`extern void dispatch_sync_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_sync_f)

Submits an app-defined function for synchronous execution on a dispatch queue.

[`extern void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);`](/documentation/Dispatch/dispatch_barrier_sync)

Submits a barrier block object for execution and waits until that block completes.

[`extern void dispatch_barrier_sync_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_barrier_sync_f)

Submits a barrier function for execution and waits until that function completes.

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

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

[`extern void dispatch_async_and_wait_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_async_and_wait_f)

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

[`extern void dispatch_barrier_async_and_wait(dispatch_queue_t queue, dispatch_block_t block);`](/documentation/Dispatch/dispatch_barrier_async_and_wait)

Submits a work item for synchronous execution and marks the work as a barrier for subsequent concurrent tasks.

[`extern void dispatch_barrier_async_and_wait_f(dispatch_queue_t queue, void *context, dispatch_function_t work);`](/documentation/Dispatch/dispatch_barrier_async_and_wait_f)

Submits a function-based work item for synchronous execution and marks the work as a barrier for subsequent concurrent tasks.

### Managing Queue Attributes

[`extern const char *dispatch_queue_get_label(dispatch_queue_t queue);`](/documentation/Dispatch/dispatch_queue_get_label)

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

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

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



---

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)