group.h

Introduction

Use the links in the table of contents to the left to access the documentation.



Functions

dispatch_group_async

Submits a block to a dispatch queue and associates the block with the given dispatch group.

dispatch_group_async_f

Submits a function to a dispatch queue and associates the block with the given dispatch group.

dispatch_group_create

Creates new group with which blocks may be associated.

dispatch_group_enter

Manually indicate a block has entered the group

dispatch_group_leave

Manually indicate a block in the group has completed

dispatch_group_notify

Schedule a block to be submitted to a queue when all the blocks associated with a group have completed.

dispatch_group_notify_f

Schedule a function to be submitted to a queue when all the blocks associated with a group have completed.

dispatch_group_wait

Wait synchronously until all the blocks associated with a group have completed or until the specified timeout has elapsed.


dispatch_group_async


Submits a block to a dispatch queue and associates the block with the given dispatch group.

#if (defined( 1)) 
 (
    macos(
        10.6),
    ios(
        4.0))  void dispatch_group_async(
    dispatch_group_t group, 
    dispatch_queue_t queue, 
    dispatch_block_t block);  
#endif 
/* __BLOCKS__ */
Parameters
group

A dispatch group to associate with the submitted block. The result of passing NULL in this parameter is undefined.

queue

The dispatch queue to which the block will be submitted for asynchronous invocation.

block

The block to perform asynchronously.

Discussion

Submits a block to a dispatch queue and associates the block with the given dispatch group. The dispatch group may be used to wait for the completion of the blocks it references.


dispatch_group_async_f


Submits a function to a dispatch queue and associates the block with the given dispatch group.

(
    macos(
        10.6),
    ios(
        4.0)) DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_NONNULL4  void dispatch_group_async_f(
    dispatch_group_t group, 
    dispatch_queue_t queue, 
    void *_Nullable context, 
    dispatch_function_t work);  
Parameters
group

A dispatch group to associate with the submitted function. The result of passing NULL in this parameter is undefined.

queue

The dispatch queue to which the function will be submitted for asynchronous invocation.

context

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

work

The application-defined function to invoke on the target queue. The first parameter passed to this function is the context provided to dispatch_group_async_f().

Discussion

See dispatch_group_async() for details.


dispatch_group_create


Creates new group with which blocks may be associated.

(
    macos(
        10.6),
    ios(
        4.0)) DISPATCH_MALLOC DISPATCH_RETURNS_RETAINED   dispatch_group_t dispatch_group_create(
    void);  
Return Value

The newly created group, or NULL on failure.

Discussion

This function creates a new group with which blocks may be associated. The dispatch group may be used to wait for the completion of the blocks it references. The group object memory is freed with dispatch_release().


dispatch_group_enter


Manually indicate a block has entered the group

(
    macos(
        10.6),
    ios(
        4.0))  void dispatch_group_enter(
    dispatch_group_t group);  
Parameters
group

The dispatch group to update. The result of passing NULL in this parameter is undefined.

Discussion

Calling this function indicates another block has joined the group through a means other than dispatch_group_async(). Calls to this function must be balanced with dispatch_group_leave().


dispatch_group_leave


Manually indicate a block in the group has completed

(
    macos(
        10.6),
    ios(
        4.0))  void dispatch_group_leave(
    dispatch_group_t group);  
Parameters
group

The dispatch group to update. The result of passing NULL in this parameter is undefined.

Discussion

Calling this function indicates block has completed and left the dispatch group by a means other than dispatch_group_async().


dispatch_group_notify


Schedule a block to be submitted to a queue when all the blocks associated with a group have completed.

#if (defined( 1)) 
 (
    macos(
        10.6),
    ios(
        4.0))  void dispatch_group_notify(
    dispatch_group_t group, 
    dispatch_queue_t queue, 
    dispatch_block_t block);  
#endif 
/* __BLOCKS__ */
Parameters
group

The dispatch group to observe. The result of passing NULL in this parameter is undefined.

queue

The queue to which the supplied block will be submitted when the group completes.

block

The block to submit when the group completes.

Discussion

This function schedules a notification block to be submitted to the specified queue once all blocks associated with the dispatch group have completed.

If no blocks are associated with the dispatch group (i.e. the group is empty) then the notification block will be submitted immediately.

The group will be empty at the time the notification block is submitted to the target queue. The group may either be released with dispatch_release() or reused for additional operations. See dispatch_group_async() for more information.


dispatch_group_notify_f


Schedule a function to be submitted to a queue when all the blocks associated with a group have completed.

(
    macos(
        10.6),
    ios(
        4.0)) DISPATCH_NONNULL1 DISPATCH_NONNULL2 DISPATCH_NONNULL4  void dispatch_group_notify_f(
    dispatch_group_t group, 
    dispatch_queue_t queue, 
    void *_Nullable context, 
    dispatch_function_t work);  
Parameters
group

The dispatch group to observe. The result of passing NULL in this parameter is undefined.

context

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

work

The application-defined function to invoke on the target queue. The first parameter passed to this function is the context provided to dispatch_group_notify_f().

Discussion

See dispatch_group_notify() for details.


dispatch_group_wait


Wait synchronously until all the blocks associated with a group have completed or until the specified timeout has elapsed.

(
    macos(
        10.6),
    ios(
        4.0))  intptr_t dispatch_group_wait(
    dispatch_group_t group,
    dispatch_time_t timeout);  
Parameters
group

The dispatch group to wait on. The result of passing NULL in this parameter is undefined.

timeout

When to timeout (see dispatch_time). As a convenience, there are the DISPATCH_TIME_NOW and DISPATCH_TIME_FOREVER constants.

Return Value

Returns zero on success (all blocks associated with the group completed within the specified timeout) or non-zero on error (i.e. timed out).

Discussion

This function waits for the completion of the blocks associated with the given dispatch group, and returns after all blocks have completed or when the specified timeout has elapsed.

This function will return immediately if there are no blocks associated with the dispatch group (i.e. the group is empty).

The result of calling this function from multiple threads simultaneously with the same dispatch group is undefined.

After the successful return of this function, the dispatch group is empty. It may either be released with dispatch_release() or re-used for additional blocks. See dispatch_group_async() for more information.


Typedefs

dispatch_group_t

A group of blocks submitted to queues for asynchronous invocation.


dispatch_group_t


A group of blocks submitted to queues for asynchronous invocation.

typedef struct dispatch_group_s *dispatch_group_t;