Function

dispatch_barrier_sync

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

Declaration

void dispatch_barrier_sync(dispatch_queue_t queue, dispatch_block_t block);

Parameters

queue

The dispatch queue on which to execute the barrier block. This parameter cannot be NULL.

block

The barrier block to be executed. This parameter cannot be NULL.

Discussion

Submits a barrier block to a dispatch queue for synchronous execution. Unlike dispatch_barrier_async, this function does not return until the barrier block has finished. Calling this function and targeting the current queue results in deadlock.

When the barrier block reaches the front of a private concurrent queue, it is not executed immediately. Instead, the queue waits until its currently executing blocks finish executing. At that point, the queue executes the barrier block by itself. Any blocks submitted after the barrier block are not executed until the barrier block completes.

The queue you specify should be a concurrent queue that you create yourself using the dispatch_queue_create function. If the queue you pass to this function is a serial queue or one of the global concurrent queues, this function behaves like the dispatch_sync function.

Unlike with dispatch_barrier_async, no retain is performed on the target queue. Because calls to this function are synchronous, it "borrows" the reference of the caller. Moreover, no Block_copy is performed on the block.

As an optimization, this function invokes the barrier block on the current thread when possible.

See Also

Creating a Barrier Synchronously

dispatch_barrier_sync_f

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