1 .\" Copyright (c) 2008-2009 Apple Inc. All rights reserved.
3 .Dt dispatch_group_create 3
6 .Nm dispatch_group_create ,
7 .Nm dispatch_group_async ,
8 .Nm dispatch_group_wait ,
9 .Nm dispatch_group_notify
10 .Nd group blocks submitted to queues
12 .Fd #include <dispatch/dispatch.h>
14 .Fo dispatch_group_create
18 .Fo dispatch_group_enter
19 .Fa "dispatch_group_t group"
22 .Fo dispatch_group_leave
23 .Fa "dispatch_group_t group"
26 .Fo dispatch_group_wait
27 .Fa "dispatch_group_t group" "dispatch_time_t timeout"
30 .Fo dispatch_group_notify
31 .Fa "dispatch_group_t group" "dispatch_queue_t queue" "void (^block)(void)"
34 .Fo dispatch_group_notify_f
35 .Fa "dispatch_group_t group" "dispatch_queue_t queue" "void *context" "void (*function)(void *)"
38 .Fo dispatch_group_async
39 .Fa "dispatch_group_t group" "dispatch_queue_t queue" "void (^block)(void)"
42 .Fo dispatch_group_async_f
43 .Fa "dispatch_group_t group" "dispatch_queue_t queue" "void *context" "void (*function)(void *)"
46 A dispatch group is an association of one or more blocks submitted to dispatch
47 queues for asynchronous invocation.
48 Applications may use dispatch groups to
49 wait for the completion of blocks associated with the group.
52 .Fn dispatch_group_create
53 function returns a new and empty dispatch group.
56 .Fn dispatch_group_enter
58 .Fn dispatch_group_leave
59 functions update the number of blocks running within a group.
62 .Fn dispatch_group_wait
63 function waits until all blocks associated with the
65 have completed, or until the specified
70 becomes empty within the specified amount of time, the function will return zero
71 indicating success. Otherwise, a non-zero return code will be returned.
73 .Va DISPATCH_TIME_FOREVER
76 calls to this function will wait an unlimited amount of time until the group
77 becomes empty and the return value is always zero.
80 .Fn dispatch_group_notify
81 function provides asynchronous notification of the completion of the blocks
88 once all blocks associated with the
91 The system holds a reference to the dispatch group while an asynchronous
92 notification is pending, therefore it is valid to release the
94 after setting a notification block.
95 The group will be empty at the time the notification block is submitted to the
96 target queue. The group may either be released with
98 or reused for additional operations.
101 .Fn dispatch_group_async
102 convenience function behaves like so:
105 dispatch_group_async(dispatch_group_t group, dispatch_queue_t queue, dispatch_block_t block)
107 dispatch_retain(group);
108 dispatch_group_enter(group);
109 dispatch_async(queue, ^{
111 dispatch_group_leave(group);
112 dispatch_release(group);
118 .Fn dispatch_group_create
119 function returns NULL on failure and non-NULL on success.
122 .Fn dispatch_group_wait
123 function returns zero upon success and non-zero after the timeout expires.
125 .Va DISPATCH_TIME_FOREVER ,
127 .Fn dispatch_group_wait
128 waits forever and always returns zero.
130 Dispatch groups are retained and released via calls to
133 .Fn dispatch_release .
136 .Fn dispatch_group_async
138 .Fn dispatch_group_notify
139 functions are wrappers around
140 .Fn dispatch_group_async_f
142 .Fn dispatch_group_notify_f
145 .Xr dispatch_object 3 ,
146 .Xr dispatch_async 3 ,
147 .Xr dispatch_time 3 ,
148 .Xr dispatch_queue_create 3 ,
149 .Xr dispatch_semaphore_create 3