ios - 如果我使用多个dispatch_async会发生什么

标签 ios objective-c swift grand-central-dispatch

需要在文档目录中解压 10 个文件,因为我像这样使用调度异步

   dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH,   0), ^{
 // unzip 5 files

})
dispatch_async( dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0), ^{
// unzip another 5 files

})

我的疑问是它会同时解压缩吗?

如果是这样,当前 5 个文件解压时,另外 5 个文件也解压 同时解压?

我怎样才能有效地做到这一点?

任何帮助将不胜感激。

最佳答案

如果你解压全部文件,那就太好了。因为它是异步的。在同时进行后台操作时,如果你尝试执行其他后台进程,则会出现问题。

DISPATCH_QUEUE_PRIORITY_HIGH Items dispatched to the queue will run at high priority, i.e. the queue will be scheduled for execution before any default priority or low priority queue.

If you want to run a single independent queued operation and you’re not concerned with other concurrent operations, you can use the global concurrent queue

dispatch_queue_t globalConcurrentQueue =
dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0)

It runs asynchronously on a background thread. This is done because parsing data may be a time consuming task and it could block the main thread which would stop all animations and the application wouldn't be responsive.

Grand Central Dispatch

dispatch_async

Asynchronous Operations

Apple Document

UI and main Thread

GLobal Queue

dispatch_sync and dispatch_async Process

关于ios - 如果我使用多个dispatch_async会发生什么,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38500426/

相关文章:

swift - Swift 中对闭包的弱引用

swift - SCNCamera.exposureOffset 在 iOS13 中不起作用

ios - 如何检查此过程是否已完成?

ios - 在回调函数中调用 Objective C 方法

ios - 当每次向 iOS 中的文本字段添加三个数字时,为整数插入一个逗号

objective-c - 如何在 Objective-c 中将数组声明为常量?

objective-c - 在应用程序退出之前执行函数

ios - 想要在单击相同的 UIButton 时从 UITableViewCell 更改正确的 UIButton 图像

ios - React-Native + Apollo-Link-State + AWS Appsync : Defaults are not stored in cache

ios - 将 UITableViewCell 的高度调整为 UITextView 的高度