iOS multithreading-synchronous asynchronous serial parallel

Source: Internet
Author: User

The concept of serial parallel asynchronous synchronization is confusing, and I have an explanation for these concepts in the first GCD, but it's not clear enough, so rewrite a blog here specifically to differentiate these concepts:

Let's talk about queues and tasks:

(1) The queue is divided into serial and parallel, the execution of tasks is divided into synchronous and asynchronous, asynchronous is the pronoun of multithreading, asynchronous in the actual reference will open a new thread, execution time-consuming operation.

(2) The queue is only responsible for scheduling tasks, not responsible for the execution of tasks, the task is executed in the thread.

The above two points for understanding serial, parallel, synchronous, asynchronous is very important!

Again, the features of the queue and the task:

(1) Serial queue: The task is scheduled in order, the previous task does not complete, the queue will not be dispatched.

(2) Parallel queue: As long as there are idle threads, the queue will dispatch the current task, to the thread to execute, do not need to consider whether there is a task in front of the execution, as long as the thread can be exploited, the queue will dispatch the task.

(3) Task Synchronous execution: New threads are not opened and tasks are executed sequentially.

(4) The task executes asynchronously: A new thread is opened and the task can be executed concurrently.

Then one would ask, since the most efficient asynchronous execution still has to do with synchronization, let me give you a simple example:

When two or more two threads share some resources or need to mate to do some work, the order in which each thread runs must be reconciled through thread synchronization . For example, when the thread A and B work together, a to a certain extent, a to rely on a certain result of B, so stop, motioned B to run, B according to the words, then the results to a;a to continue operation. or when threads A and B share a resource, if the resource is read and written at the same time, there is a problem of resource contention , and only one thread is allowed to occupy the resource at some point in time, while another thread is waiting, which is also thread synchronization .

iOS multithreading-synchronous asynchronous serial parallel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.