When does anyone want to use NSThreads via GCD?

Are there any cases when someone wants to use raw NSThreads instead of GCD for concurrency? I like GCD, but I want to know if I will use NSThreads for Cocoa / Cocoa-Touch in the end.

+7
source share
3 answers

I use pthread for control, good performance and portability. sometimes you can use NSThread for the optional NSObject mate that it offers.

There are several lower-level interfaces where you need to coordinate the threads with the API you are using (for example, in real-time I / O or rendering). sometimes you have the flexibility to use the thread, sometimes in this situation it is convenient to use NSThread , so you can easily use the CF or NS startup loops with these interfaces. Thus, the startup loop parameter that you configured in your thread is more likely to be of interest to the API than the thread itself. in these cases, GCD may not necessarily be an alternative.

but ... most developers do not need to go to these levels often.

+5
source

You will hardly need to use the NSThread / pthread API directly on OS X or iOS. On other platforms, perhaps yes (although GCD is becoming more widespread in BSD, Linux and even Windows - see the Wikipedia page for Grand Central Dispatch), but on Apple OS platforms you will almost always get the best result by allowing the system to control life cycle flows for you. The only time you might want to do your own thread management is in real-time scenarios in which you need to control thread priorities and have direct control over thread latency, balancing the amount of work that each thread does manually.

+3
source

There may be some special situations where you need to do something strange that cannot be done with the GCD. But all you can do with a GCD is to do so (GCDs and streams are not mutually exclusive, if you really need to use a stream that you don't need, you should not modify any GCD material that you already have) .

Not sure, whatever the case. Maybe if you need to configure a secondary specialized RunLoop (not sure if this can be done with a GCD, but, of course, with a stream). Or maybe there is some other special case that I cannot understand at the moment.

+2
source

All Articles