Are there any cases when anyone would want to use raw NSThreads instead of GCD for concurrency? I love the GCD, but I want to know if I will need to use NSThreads for Cocoa/Cocoa-Touch eventually.
From what I read online, GCD seems to do the exact same thing as basic threads (POSIX, NSThreads etc.) while adding much more technical jargon ("blocks"). It seems to just overcomplicate the basic thread creation system (create thread, run function).
Once you dispatch a task using Grand Central Dispatch, you no longer have control or insight into the execution of that task. The NSOperation API is more flexible in that respect, giving the developer control over the operation's life cycle.
In apple document, GCD is Thread-Safe that means multiple thread can access.
The 64 thread width limit of GCD is undocumented because a well-designed concurrency architecture shouldn't depend on the queue width. You should always design your concurrency architecture such that a 2 thread wide queue would eventually finish the job to the same result (if slower) as a 1000 thread wide queue.
i use pthread
s for control, good performance, and portability. sometimes, you might opt to use NSThread
for the extra NSObject
interfacing it offers.
there are a few lower level interfaces where you need to coordinate threads with the APIs you use (e.g. realtime I/O or rendering). sometimes you have flexibility regarding the thread you use, sometimes it is convenient to use NSThread
in this situation so you can easily use CF or NS run loops with these interfaces. So the run loop parameter you set up on your thread is likely of more interest to the API than the thread itself. in these cases, GCD may not necessarily be an alternative.
but… most devs won't need to drop to these levels often.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With