0
votes

Apple says that Operation queues usually provide the threads used to run their operations. In OS X v10.6 and later, operation queues use the libdispatch library (also known as Grand Central Dispatch) to initiate the execution of their operations. As a result, operations are always executed on a separate thread, regardless of whether they are designated as concurrent or non-concurrent operations.

As far as i understood from above lines that NSOperationQueue executes operations in parallel, lets put dependency thought aside.

I need to know does really NSOperationQueue initiate all operation in parallel? Does it call -start method of each operation at a moment or one by one in queue order?

2
How have you configured the queue? Did you try testing it?Wain

2 Answers

1
votes

As Tim has already answered, look at the maxConcurrentOperationCount, if you set this to 1, the operations will be executed in serial.

In addition, if you are concerned about the order in which operations are executed but want to utilize parallel execution, you can set up dependencies between NSOperation objects really simple by calling - (void)addDependency:(NSOperation *)operation.

For example, you need that operation1 is executed BEFORE operation 2, you would to something like this:

NSOperation *operation1;
NSOperation *operation2;
[operation2 addDependency:operation1];
0
votes

You might be interested in the maxConcurrentOperationCount property of an NSOperationQueue - it determines how many tasks the queue is allowed to start at a time.