ios - Does dispatch_group_wait allow cutting in line? -
this question grand central dispatch, , dispatch_group_wait()
in particular.
assume dispatch_group
called group
10 tasks in waiting performed.
elsewhere have task needs wait tasks in group
finish before executes. make happen, use dispatch_group_wait(group, dispatch_time_forever)
.
to distinguish tasks in group
i'll call lonelytask
.
if task gets added group
while lonelytask
waiting, gets executed first, lonelytask
or task added group
? in other words, tasks added group
while task waiting execute "cut in line" ahead of waiting task, or order in called maintained?
i have searched documentation, haven't been able find answer question...
group +/- counter (semaphore) fires each time reaches zero. unaware of tasks, because dispatch_group_async() wrapper enter()s group before task submission , enqueues new block call task's block , leave() group. that's all. groups may used without queues asynchronous retain-counters or sml that.
so in general "you can't".
but if able [re]target (dispatch_set_target_queue()) related queues single concurrent queue, dispatch_barrier_async() on queue may want, if called in proper isolation. note group has nothing @ all.
also, original lonelytask not task group's point of view — unrelated thread of execution waits until group balanced. synonym "cutting in line" "barrier".
another approach create private group each taskset , wait specific group. not insert barrier though — following tasks not wait completion of lonelytask , uncontrolled async()s may "break rules", leading funny debugging sessions.
Comments
Post a Comment