synchronous, asynchronous, serial, concurrent
Synchronous and asynchronous representations will not open new threads. Serial and concurrent representation of how tasks are performed.
Synchronous serial and synchronous concurrency, the way the task executes is the same. There is no difference, because no new threads are opened, and all tasks are performed within a thread.
Asynchronous serial and asynchronous concurrency, the way the task executes is different, asynchronous serial will open up a new thread, all the tasks in the queue are executed one at a time in the order of addition, asynchronous concurrency will open up multiple threads, and as to how many threads to open up, it is up to the system, but all tasks seem to be executed concurrently.
Ways to queue up:
dispatch_queue_t myqueue = dispatch_queue_create ("Myqueue", NULL);
/**
Parameter 1: label, used to distinguish the queue
Parameter 2: The type of queue, indicating whether this queue is a serial or concurrent queue null represents a serial queue,
Dispatch_queue_concurrent represents a concurrent queue
*/
How to execute a queue
Asynchronous execution
Dispatch_async (< #dispatch_queue_t queue#>, <#^ (void) block#>)
Synchronous execution
Dispatch_sync (< #dispatch_queue_t queue#>, <#^ (void) block#>)
Primary queue
Master queue: A task that is specifically responsible for scheduling the main line level, and there is no way to open new threads. Therefore, tasks under the main queue, whether asynchronous or synchronous, do not open threads, and the task executes only in the main thread order.
Primary queue Asynchronous Task: The task is now placed in the primary queue, but not immediately, until all other tasks in the main queue that are added to the home column are executed before the tasks we add using code are executed.
Main Queue Synchronization task: Easy to block the main thread, so do not write this. Cause: Our own code task needs to be executed immediately, but the main thread is executing the method body of the code task, so the code task must wait, and the main thread is waiting for the code task to complete the following tasks, thus forming a mutual wait. The entire main thread is blocked.
Global queue
Global queue: The essence is a concurrent queue, provided by the system for easy programming and can be used directly without creating.
method to get the global queue: dispatch_get_global_queue (long indentifier.unsigned long flags)
/**
Parameter description:
Parameter 1: Represents the priority of the task, the default write 0 is the line, do not use the system-provided enumeration type, because iOS7 and iOS8 enumeration values are different, the use of numbers can be generalized.
Parameter 2: Apple retains the keyword, generally also write 0
*/
Differences between a global queue and a concurrent queue:
1, the global queue has no name, but the concurrent queue has a name. A name makes it easy to view the system log
2, the global queue is shared by all applications.
3, in the MRC, the global queue is not released manually, but the concurrent queue is required.
IOS Home column, global queue relationship