The setQueuePriority function has different performance on the iOS emulator and on the iPhone

I have two NSIvocationOperations in one NSOperationQueue. And I used setQueuePriority to adjust the execution order of two operations: 1-> 2 or 2-> 1. However, the code worked on the emulator, but failed on my iPhone.

My code looks like this:

NSOperationQueue *operationQueue = [[NSOperationQueue alloc] init]; operationQueue.maxConcurrentOperationCount = 1; NSInvocationOperation *operation1 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread1) object:nil]; [operation1 setQueuePriority:NSOperationQueuePriorityVeryLow]; NSInvocationOperation *operation2 = [[NSInvocationOperation alloc] initWithTarget:self selector:@selector(thread2) object:nil]; [operation2 setQueuePriority:NSOperationQueuePriorityHigh]; [operationQueue addOperation:operation1]; [operationQueue addOperation:operation2]; 

Operation2 must be performed before operation1, and I saw the same result on the emulator. While on iPhone, operation1 was always performed first, regardless of how I adjusted their QueuePriorities. Why is this so?

+1
source share
1 answer

Queue priority does not guarantee order completion. To quote from Apple documentation:

You should use priority values ​​only as needed to classify the relative priority of independent operations. Priority values ​​should not be used to implement dependency management between different operations of objects.

If it is important for you that one operation is performed before another, you should use operational dependencies (via addDependency: .

0
source

All Articles