<!--
{
  "availability" : [
    "iOS: 12.0.0 -",
    "iPadOS: 12.0.0 -",
    "macCatalyst: 13.1.0 -",
    "macOS: 10.14.0 -",
    "tvOS: 12.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 5.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "Dispatch",
  "identifier" : "/documentation/Dispatch/dispatch_barrier_async_and_wait_f",
  "metadataVersion" : "0.1.0",
  "role" : "Function",
  "symbol" : {
    "kind" : "Function",
    "modules" : [
      "Dispatch"
    ],
    "preciseIdentifier" : "c:@F@dispatch_barrier_async_and_wait_f"
  },
  "title" : "dispatch_barrier_async_and_wait_f"
}
-->

# 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.

```
extern void dispatch_barrier_async_and_wait_f(dispatch_queue_t queue, void *context, dispatch_function_t work);
```

## Parameters

`queue`

The queue on which to submit the function. This parameter cannot be `NULL`.

`context`

The app-defined context parameter to pass to the function.

`work`

The app-defined function to invoke on the target queue. The first parameter passed to this function is the value in the `context` parameter. This parameter cannot be `NULL`.

## Discussion

This function submits work to the specified queue for execution. Unlike [`dispatch_async`](/documentation/Dispatch/dispatch_async), this function does not return until after the `work` function finishes. Calling this function and targeting the current queue results in deadlock.

When submitted to a concurrent queue, the `work` function doesn’t run until all previously submitted tasks finish executing, and subsequently submitted tasks don’t execute until after the `work` function finishes. You use barriers to ensure the correct execution order of relevant work. For example, you might use them in reader/writer schemes where the order of read and write tasks is significant. If you submit the work to a nonconcurrent queue, this method behaves identically to [`asyncAndWait(execute:)`](/documentation/Dispatch/DispatchQueue/asyncAndWait(execute:)-1udeu).

Unlike [`sync(execute:)`](/documentation/Dispatch/DispatchQueue/sync(execute:)-3segw), this function respects all attributes of the queue when it executes the `work` function. For example, it respects the quality-of-service level and autorelease frequency of the target queue.

If the runtime has already brought up a thread to service asynchronous work items, the system uses that same thread to execute any synchronous tasks you submitted using this function. If the runtime hasn’t brought up a thread to service asynchronous work items, the sytem executes these synchronous tasks on the current thread as an optimization. However, these optimizations apply only when `queue` targets a global concurrent queue. If it targets any other queue, the system executes the work on that queue’s thread. For example, if `queue` targets the main queue, the `work` function always runs on the main thread.

Unlike with [`dispatch_async`](/documentation/Dispatch/dispatch_async), this method doesn’t retain the `queue` object. Because calls to this function are synchronous, it “borrows” the reference of the caller.

---

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)