Question

I am very new to GCD and threading. I have gone through the tutorials and getting very much confusion. Can some one explain in simple words.Please don't suggest apple developer links..

Thanks in advance !

Was it helpful?

Solution

NSOperationQueue can be more suitable for long-running operations that may need to be cancelled or have complex dependencies. GCD dispatch queues are better for short tasks that should have minimum performance and memory overhead.

It is possible to cancel operations that have been enqueued in an NSOperationQueue (as far as the operations support it). When you enqueue a block in a GCD dispatch queue, it will definitely be executed at some point.

check the below link,it may be helpful to you.

Operation Queue vs Dispatch Queue for iOS Application

OTHER TIPS

Operations provide us more control over the task like we can cancel a particular operation when ever we want or all operations at the same time. But this same thing can not be done using Dispatch Queues.

Further Dispatch Queues work on the concept of FIFO and where as the Operations does not.

For Operation we can prioritize the task and have control over them like which task to be executed first and which to be in the end by defining their priority.

Which is done by setting a property named "queuePriority" to be very low, low, normal, high, very high. many other such things can be done suing Operations and not by Dispatch Queues.

With Operations we can not do things serially as they are concurrent by default but this can also be achieved by adding dependencies of operations on each other like operation 2 is dependent over operation 1 and operation 3 is dependent on operation 2. Hence by doing this they will execute serially.

GCD is lower-level than NSOperationQueue, its major advantage is that its implementation is very light-weight and focused on lock-free algorithms and performance.

In general, you should use the highest level of abstraction that suits your needs. This means that you should usually use NSOperationQueue instead of GCD. NSOperationQueue gives you a lot more control over how your operations are executed.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top