The relationship between synchronous, asynchronous, and queue in iOS multi-threading

Source: Internet
Author: User

Synchronous and asynchronous

Async: Refers to multithreading, the ' corresponding code ' is put in other threads to execute, the current thread of the code will continue to execute, do not need to wait until the code is placed in the child thread execution completed.

Synchronous execution function: This actual application scenario is not many, understand can

Login, registration needs to be placed in a queue to execute

The download file needs to be placed in a different queue to execute

Execute functions asynchronously:

Serial Queue features: If you want to turn on a thread, only one thread is turned on

(When the synchronization function executes, if the queue is a serial queue, no threads need to be opened and the task executes in the current thread)

(When an asynchronous function executes, if the queue is a serial queue, the thread can be turned on and only one thread will be opened)

Concurrent Queue Features: Multiple threads can be opened, iOS8 the number of previously open threads is limited. You can open many threads later.

(When the synchronization function executes, if the queue is a concurrent queue, no threads need to be opened and the task executes in the current thread)

(When an asynchronous function executes, if the queue is a concurrent queue, the thread can be turned on and multiple threads can be opened)

When the execution function and the queue are used in combination: * * * does not open threads and queues are not related, only by the execution function decision.

Several threads are determined by the queue and are not related to the execution function (serial, one-----concurrent, multiple).

Global queue: A concurrent queue that the system provides to us

Main queue: Placing a task in the main queue represents the code in the main thread to execute the task

-----------------------

Attention:

Dispatch_after This function executes the task asynchronously regardless of what the queue is

If the execution queue is the home column, the execution function does not open the new thread

The relationship between synchronous, asynchronous, and queue in iOS multi-threading

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.