Waiting on Groups of Queued Tasks (dispatch_group_async)

来源:互联网 发布:如何提高淘宝心的级别 编辑:程序博客网 时间:2024/05/18 03:35
<div class="page" title="Page 54"><div class="layoutArea"><div class="column"><p><span style="font-size: 10pt; font-family: MyriadSet;">// Waiting on asynchronous tasks </span></p></div></div></div>
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);dispatch_group_t group = dispatch_group_create();// Add a task to the groupdispatch_group_async(group, queue, ^{   // Some asynchronous work});// Do some other work while the tasks execute.// When you cannot make any more forward progress,// wait on the group to block the current thread.dispatch_group_wait(group, DISPATCH_TIME_FOREVER);// Release the group when it is no longer needed.dispatch_release(group);

0 0