The NSOperation execution line depends on the NSOperationQueue where you added the operation. See this expression in your code -
[[NSOperationQueue mainQueue] addOperation:yourOperation]; // or any other similar add method of NSOperationQueue class
All this assumes that you have not yet executed the thread in the main NSOperation method, which is the actual monster in which the working instructions (which are expected) are written.
However, in the case of simultaneous operations, the scenario is different. A queue can spawn a thread for each concurrent operation. Although this is not guaranteed, and it depends on the system resources and the requirements of the work resource at that moment in the system. You can control the concurrency of the work queue with the maxConcurrentOperationCount property.
EDIT -
I found your question interesting and made the analysis / log itself. I have an NSOperationQueue created in the main thread, like this -
self.queueSendMessageOperation = [[[NSOperationQueue alloc] init] autorelease]; NSLog(@"Operation queue creation. current thread = %@ \n main thread = %@", [NSThread currentThread], [NSThread mainThread]); self.queueSendMessageOperation.maxConcurrentOperationCount = 1;
And then I continued to create NSOperation and added it using addOperation. In the main method of this operation, when I checked the current thread,
NSLog(@"Operation obj = %@\n current thread = %@ \n main thread = %@", self, [NSThread currentThread], [NSThread mainThread]);
it was not the main stream. And I found that the current stream object is not an object of the main stream.
Thus, user queuing in the main thread (without concurrency among its operations) does not necessarily mean that the operations will be performed sequentially along the main thread.
Ashok Oct 30 '13 at 5:07 on 2013-10-30 05:07
source share