Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is [NSOperationQueue mainQueue] guaranteed to be serial?

That is, if we queue the same thing several time there will be no concurrency. The one we queued first will be executed first.

I mean there is only one main thread right?

like image 679
user4951 Avatar asked Jan 13 '23 18:01

user4951


2 Answers

I have found a nice answer here:

NSOperationQueue and concurrent vs non-concurrent

So make all added operations serial you can always set:

[[NSOperationQueue mainQueue] setMaxConcurrentOperationCount:1];

like image 94
B.S. Avatar answered Jan 19 '23 11:01

B.S.


And the answer is... YES and NO

when you create a new NSOperation to add to your queue, you can use

- (void)setQueuePriority:(NSOperationQueuePriority)priority

according to the documentation, the queue will use this priority, and other factors as inter dependency to decide what operation will be executed next.

As long as your operations have the same priority and no inter-operation dependencies, they should be executed in the same order you added them, maybe with other, system related operations, inserted between them.

like image 23
Jerome Diaz Avatar answered Jan 19 '23 12:01

Jerome Diaz