Dispatch Queues
Dispatch queues is a series of custom task actions based on the C mechanism. Follow the FIFO rules. Only one task is executed at a time, and the new task is not performed until the last task is completed. Conversely, the concurrent dispatch queue can start multiple tasks without waiting for other tasks to complete.
The task submitted to the dispatch queue must be a encapsulated method or block object. The dispatch queue is part of the GCD technology.
Dispatch Sources
Dispatch sources is a C-mechanism-based asynchronous system event. A dispatch source encapsulates a specific system event type information and commits the specified block object or method to the dispatch queue when an event occurs. You can use dispatch sources to map the following types of system events:
Timers
Signal handlers
descriptor-related Events
process-related Events
Mach Port Events
Custom events that you trigger
Dispatch sources is part of the GCD.
Operation Queues
The operation queue is equivalent to the Concurrency dispathc Queuew execution class is nsoperationqueue. Dispatch queue always follows the FIFO rule, operation Queues always consider other factors when deciding on the order of task execution. An important one of these factors is whether the current task relies on the completion of other tasks. When you define a task, you specify a dependency to create a more complex order of execution.
The instance submitted to the operation queue must be an Nsoperation class instance. A Operation object is a objective C object that encapsulates the tasks you want to perform and all the data you need. Because the Nsoperation class is an abstract class, you need to customize the subclasses for the task.
The Operation object produces Key-value observer notifications.
Asynchronous Design Techniques
You need to first consider whether you really need a practical concurrency mechanism. Because this is more complex and more difficult to debug. Improper design can reduce the speed and speed of the code. Here are a few design recommendations for your reference.
First, it is necessary to first enumerate the tasks performed by the application and the data structures and objects corresponding to each task. These objects can be modified concurrently if the object's modifications do not affect other objects.
Second, if you change the order of task execution to change the result, you might also use a traditional serial step. If the order of change does not affect the output, then you should consider concurrent execution of the task. And don't worry about the task too much.
Concurrency and Application Design (ii)