iphone - NSRunLoops in Cocoa? -
let's have 2 threads, 1 main thread , one, secondary thread. main thread being used most, (rarely) want secondary thread work based on calls main thread. of time secondary thread should sleep. after searching understand way use runloops. tried read apple's docs (http://developer.apple.com/library/ios/#documentation/cocoa/conceptual/multithreading/runloopmanagement/runloopmanagement.html#//apple_ref/doc/uid/10000057i-ch16-sw5)
but looks me complex , i'm having hard time there. there elegant , simple way achieve described? similar runloop code examples out there can run , play with?
thanks
matt gallagher has nice blog article comparing secondary thread approach other ways of getting background work done.
http://cocoawithlove.com/2010/09/overhead-of-spawning-threads.html
in case, don't have concerned thread-creation overhead. matt's code examples might provide insight managing secondary thread's runloop.
all said, go joshua's advice , use nsoperationqueue , nsoperation background work. if work encapsulated in nsinvocation, can use nsinvocationoperation , avoid nsoperation subclass.
Comments
Post a Comment