19

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 !

Youngwing
  • 577
  • 2
  • 6
  • 24
  • Well in that case I can suggest SO links :) .. Here hope you find them useful ... http://stackoverflow.com/questions/7078658/operation-queue-vs-dispatch-queue-for-ios-application http://stackoverflow.com/questions/10373331/nsoperation-vs-grand-central-dispatch http://stackoverflow.com/questions/11676629/ios-dispatch-async-vs-nsoperationqueue And two external links :- http://maniacdev.com/2010/03/easier-threading-with-nsoperation-for-better-performance http://blog.spec-india.com/difference-between-nsthread-and-nsoperation – IronManGill Jul 11 '13 at 11:06

3 Answers3

18

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

Community
  • 1
  • 1
Sabareesh
  • 3,585
  • 2
  • 24
  • 42
  • I have seen your answer regarding background process in [THIS](http://stackoverflow.com/questions/3762200/how-to-keep-an-iphone-app-running-on-background-fully-operational/17554514#17554514) link.I need to run a recorder application for long time.Point me in the right way – Youngwing Jul 16 '13 at 06:19
4

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.

Swifty Codes
  • 992
  • 10
  • 23
1

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.

Bhavin_m
  • 2,746
  • 3
  • 30
  • 49
  • Thanks for reply .. I heard that GCD is more convenient to use while the other having over head weight (Based on few tutorials..) – Youngwing Jul 11 '13 at 13:06