Function

dispatch_apply_f

Submits a single function to the dispatch queue and causes the function to be executed the specified number of times.

Declaration

void dispatch_apply_f(size_t iterations, dispatch_queue_t queue, void *context, void (*work)(void *, size_t));

Parameters

iterations

The number of iterations to perform.

queue

The queue on which to submit the function. It is recommended that you specify DISPATCH_APPLY_AUTO for this parameter, as that causes the block to run on a queue whose quality-of-service class is most appropriate for the current execution context.

context

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

work

The application-defined function to invoke on the target queue. This parameter cannot be NULL. The block has no return value and takes the following parameters:

data

The pointer you specified in the context parameter.

iteration

The current iteration index.

Discussion

This function submits an application-defined function to a dispatch queue for multiple invocations and waits for all iterations of the function to complete before returning. If the target queue is a concurrent queue returned by dispatch_get_global_queue, the function 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 function.

See Also

Executing a Task in Parallel

dispatch_apply

Submits a single block to the dispatch queue and causes the block to be executed the specified number of times.

Beta Software

This documentation contains preliminary information about an API or technology in development. This information is subject to change, and software implemented according to this documentation should be tested with final operating system software.

Learn more about using Apple's beta software