You are correct that you will be connected with I / O, of course. And this will be compounded by the possibility of random access to the opening of several files and their active reading at the same time.
Thus, you need to pick up a little balance. Most likely, one file is not the most efficient, as you noticed.
Personally?
I would use a send semaphore.
Sort of:
@property(nonatomic, assign) dispatch_queue_t dataQueue; @property(nonatomic, assign) dispatch_semaphore_t execSemaphore;
and
- (void) process:(NSData *)d { dispatch_async(self.dataQueue, ^{ if (!dispatch_semaphore_wait(self.execSemaphore, DISPATCH_TIME_FOREVER)) { dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{ ... do calcualtion work here on d ... dispatch_async(dispatch_get_main_queue(), ^{ .... update main thread w/new data here .... }); dispatch_semaphore_signal(self.execSemaphore); }); } }); }
Where does it start:
self.dataQueue = dispatch_queue_create("com.yourcompany.dataqueue", NULL); self.execSemaphore = dispatch_semaphore_create(3); [self process: ...]; [self process: ...]; [self process: ...]; [self process: ...]; [self process: ...]; .... etc ....
You need to determine how best you will handle the sequence. If there are many objects, and there is the concept of cancellation, the inclusion of all things is likely to be wasteful. Likewise, you probably want to paste the URLs into files for processing, rather than NSData objects, as described above.
In any case, the above will handle three things at the same time, regardless of how many of them have been queued.