Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The execution thread of NSOperation depends on the <code>NSOperationQueue</code> where you added the operation. Look out this statement in your code - </p> <pre><code>[[NSOperationQueue mainQueue] addOperation:yourOperation]; // or any other similar add method of NSOperationQueue class </code></pre> <p>All this assumes you have not done any further threading in <code>main</code> method of <code>NSOperation</code> which is the actual monster where the work instructions you have (expected to be) written.</p> <p>However, in case of concurrent operations, the scenario is different. The queue may spawn a thread for each concurrent operation. Although it's not guarrantteed and it depends on system resources vs operation resource demands <em>at that point</em> in the system. You can control concurrency of operation queue by it's <code>maxConcurrentOperationCount</code> property.</p> <p><strong>EDIT</strong> -</p> <p>I found your question interesting and did some analysis/logging myself. I have NSOperationQueue created on main thread like this -</p> <pre><code>self.queueSendMessageOperation = [[[NSOperationQueue alloc] init] autorelease]; NSLog(@"Operation queue creation. current thread = %@ \n main thread = %@", [NSThread currentThread], [NSThread mainThread]); self.queueSendMessageOperation.maxConcurrentOperationCount = 1; // restrict concurrency </code></pre> <p>And then, I went on to create an NSOperation and added it using addOperation. In the main method of this operation when i checked for current thread,</p> <pre><code>NSLog(@"Operation obj = %@\n current thread = %@ \n main thread = %@", self, [NSThread currentThread], [NSThread mainThread]); </code></pre> <p>it was not as main thread. And, found that current thread object is not main thread object.</p> <p><em>So, custom creation of queue on main thread (with no concurrency among its operation) doesn't necessarily mean the operations will execute serially on main thread itself.</em></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload