0

在典型的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在这种情况下有用吗?

4

1 回答 1

-1

使用串行调度队列一次执行一项任务

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);
于 2013-03-06T11:12:02.880 回答