如何检查dispatch_async队列状态?

时间:2013-03-06 10:53:03

标签: ios objective-c

在典型的dispatch_async执行中:

dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    // ...
    dispatch_async(dispatch_get_main_queue(), ^{
        // ...
    });
});

要限制只有一个块运行:

if (_loadingFromServer) return;
_loadingFromServer = YES;
dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_BACKGROUND, 0), ^{
    // ...
    dispatch_async(dispatch_get_main_queue(), ^{
        // ...
        _loadingFromServer = NO;
    });
});

有没有办法检查异步块的运行位置,没有使用_loadingFromServer标志?

dispatch_queue_set_specific在这种情况下有用吗?

1 个答案:

答案 0 :(得分:-1)

使用Serial Dispatch Queues一次执行一项任务

http://developer.apple.com/library/ios/#documentation/General/Conceptual/ConcurrencyProgrammingGuide/OperationQueues/OperationQueues.html

喜欢这个

 dispatch_queue_t myQueue;
 myQueue = dispatch_queue_create("myQueue", NULL);
 dispatch_async(myQueue, block);