ios - is synchronous in separate thread the same as asynchronous -


recently, learning concurrency in swift. according apple's document in nsoperation class reference :

when add operation operation queue, queue ignores value of asynchronous property , calls start method separate thread. therefore, if run operations adding them operation queue, there no reason make them asynchronous.

does mean synchronous in separate thread same asynchronous? , when test following code, operation indeed doesn't block current main thread.

let operationqueue = nsoperationqueue() let operation = nsblockoperation(){     //do task here } operationqueue.addoperation(operation) 

so if true, why should create concurrency subclass of nsoperation?

oh, nsoperation. such bizarre history have.

nsoperation relatively old (in ios terms; modern in objc terms). added in os x 10.5. before os x 10.6/ios 4, there no nsblockoperation objects. there no blocks @ all. way make operation subclass or use nsinvocationoperation. both approaches cumbersome, still easier , more powerful older approach of using nsthread directly.

(this right @ time when multi-core became thing. 10.5 famous adding core animation believe first major preemptive multitasking framework in cocoa. before 10.5, things done runloop , cooperative multitasking, efficient , effective single-core systems. doesn't scale multi-core systems. tools nsoperation provided write better multi-core code, gcd so more powerful dominated how multitasking code written in cocoa.)

when subclass nsoperation, needed tell system whether operation asynchronous. isn't request run asynchronously. promise start method not block. it's start method make sure operation asynchronous.

this necessary in case nsoperation being started manually, , not needed. if put onto nsoperationqueue (and should that), property irrelevant. remember creating lot of confusion @ time.

it's become more irrelevant since introduction of blocks. easier use nsblockoperation (or dispatch_async) subclass nsoperation, bit tricky quite right.

just in case haven't read it, if want study cocoa concurrency, want start concurrency programming guide.


Comments