1 .\" Copyright (c) 2008-2010 Apple Inc. All rights reserved.
7 .Nd General manipulation of dispatch objects
9 .Fd #include <dispatch/dispatch.h>
12 .Fa "dispatch_object_t object"
16 .Fa "dispatch_object_t object"
20 .Fa "dispatch_object_t object"
24 .Fa "dispatch_object_t object"
27 .Fo dispatch_get_context
28 .Fa "dispatch_object_t object"
31 .Fo dispatch_set_context
32 .Fa "dispatch_object_t object"
36 .Fo dispatch_set_finalizer_f
37 .Fa "dispatch_object_t object"
38 .Fa "dispatch_function_t finalizer"
41 Dispatch objects share functions for coordinating memory management, suspension,
42 cancellation and context pointers. While all dispatch objects are retainable,
43 not all objects support suspension, context pointers or finalizers (currently
44 only queues and sources support these additional interfaces).
46 Objects returned by creation functions in the dispatch framework may be
47 uniformly retained and released with the functions
53 The dispatch framework does not guarantee that any given client has the last or
54 only reference to a given object. Objects may be retained internally by the
57 The invocation of blocks on dispatch queues or dispatch sources may be suspended
58 or resumed with the functions
63 The dispatch framework always checks the suspension status before executing a
64 block, but such changes never affect a block during execution (non-preemptive).
65 Therefore the suspension of an object is asynchronous, unless it is performed
66 from the context of the target queue for the given object.
67 The result of suspending or resuming an object that is not a dispatch queue or
68 a dispatch source is undefined.
71 suspension applies to all aspects of the dispatch object life cycle, including
72 the finalizer function and cancellation handler. Suspending an object causes it
73 to be retained and resuming an object causes it to be released. Therefore it is
74 important to balance calls to
78 such that the dispatch object is fully resumed when the last reference is
79 released. The result of releasing all references to a dispatch object while in
80 a suspended state is undefined.
82 Dispatch queues and sources support supplemental context pointers. The value of
83 the context pointer may be retrieved and updated with
84 .Fn dispatch_get_context
86 .Fn dispatch_set_context
89 .Fn dispatch_set_finalizer_f
90 specifies an optional per-object finalizer function that is invoked
91 asynchronously if the context pointer is not NULL when the last
92 reference to the object is released.
94 application an opportunity to free the context data associated with the object.
95 The finalizer will be run on the object's target queue.
97 The result of getting or setting the context of an object that is not a
98 dispatch queue or a dispatch source is undefined.
101 .Xr dispatch_group_create 3 ,
102 .Xr dispatch_queue_create 3 ,
103 .Xr dispatch_semaphore_create 3 ,
104 .Xr dispatch_source_create 3 ,
105 .Xr dispatch_set_target_queue 3