Is [NSOperationQueue mainQueue] a guaranteed serial number?

That is, if we queue the same thing several times, then there will be no concurrency. The first one we put in the queue will be executed first.

I mean, is there only one main thread?

+4
source share
3 answers

I found a nice answer here:

NSOperationQueue and concurrent vs non-concurrent

So, do all the added operations that you can always install:

[[NSOperationQueue mainQueue] setMaxConcurrentOperationCount:1];

+6
source

And the answer: YES and NO

when you create a new NSOperation to add in turn you can use

 - (void)setQueuePriority:(NSOperationQueuePriority)priority 

according to the documentation, the queue will use this priority, and other factors as interdependence, to decide which operation will be performed next.

As long as your operations have the same priority and are independent of interaction, they should be performed in the order in which you added them, possibly with other system-related operations inserted between them.

+2
source

From the documentation :

The NSOperationQueue class controls the execution of a set of NSOperation objects. After adding to the queue, the operation remains in this queue until it is explicitly canceled or completes its task. Operations in the queue (but not yet performed) are themselves organized in accordance with the priority levels and dependencies between operational objects and are performed accordingly . An application can create multiple queues of operations and send operations to any of them.

Dependencies between operations provide an absolute order of operations, even if these operations are located in different operational queues. An operation object is not considered ready for execution until all its dependent operations have completed execution. For operations that are ready to be executed, the queue of operations always runs the one that has the highest priority relative to other ready-made operations . For more information on how to set priority and dependency levels, see NSOperation Class Reference .

About streams :

Although you usually perform operations by adding them to the operation queue, you do not need to. You can also execute the work object manually by calling its start method, but this does not guarantee that the operation is performed simultaneously with the rest of your code. The isConcurrent method of the isConcurrent class indicates whether the operation is executed synchronously or asynchronously with respect to the thread in which its start method was called. By default, this method returns NO, which means that the operation is executed synchronously in the calling thread .

When you send a non-contact operation to the operation queue, the queue itself creates the thread on which your operation is performed. Thus, adding a noncompetitive operation to the operation queue still leads to asynchronous execution of the operation object code.

So, if I understood correctly, there will be concurrency.

+1
source

All Articles