apple说:调用此函数并针对当前队列将导致死锁!
但是这段代码很好用:
dispatch_queue_t concurrentQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_async(concurrentQueue, ^{
__block UIImage *image = nil;
dispatch_sync(concurrentQueue, ^{
/* Download the image here sync downloading */
});
dispatch_sync(dispatch_get_main_queue(), ^{
/* Show the image to the user here on the main queue */
});
});尽管我用dispatch_sync下载了映像并将块发送到相同的队列中!
发布于 2014-08-25 14:05:33
文件说:
您不应该从正在计划传递给函数的同一个队列中执行的任务调用dispatch_sync或dispatch_sync_f函数。这对于保证死锁的串行队列尤其重要,但对于并发队列也应该避免。
因为dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)是并发队列,所以它可能导致死锁,但并不总是如此。不管怎么说,这是苹果公司严格禁止的。
https://stackoverflow.com/questions/25486325
复制相似问题