Function

dispatch_apply

Submits a block to a dispatch queue for multiple invocations.

Declaration

void dispatch_apply(size_t iterations, dispatch_queue_t queue, void (^block)(size_t));

Parameters

iterations

The number of iterations to perform.

queue

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

block

The application-defined function to be submitted. This parameter cannot be NULL.

Discussion

This function submits a block to a dispatch queue for multiple invocations and waits for all iterations of the task block to complete before returning. If the target queue is a concurrent queue returned by dispatch_get_global_queue, the block can be invoked concurrently, and it must therefore be reentrant-safe. Using this function with a concurrent queue can be useful as an efficient parallel for loop.

The current index of iteration is passed to each invocation of the block.