IOS-multithreading and ios Multithreading

Source: Internet
Author: User

IOS-multithreading and ios Multithreading
I. Process

A process can be understood as an application. For example, if you open QQ, a process will be allocated to QQ in the memory; if you open it, a process will be allocated to the memory; and processes are independent of each other.

 

 

Ii. Thread 1. Basic Concepts

A thread is the basic unit of a process (it can be understood as an operation in a process). For example, QQ, many operations, such as sending files and downloading images, are subthreads.

For example, a thread in the xcode Process

 

A process has at least one thread, which is called the main thread.

All operations of a process are completed in the main thread or child thread.

 

2. Serial and parallel

Both serial and parallel are for threads.

Serial
Serial refers to the execution of tasks in a thread one by one, that is, after the previous task is completed, the next task can continue; that is, within the same time, only one task can be executed

 

 

It can be seen that the serial time consumption is the sum of all tasks.

Parallel
Parallel means that tasks in a thread can be performed simultaneously, that is, multiple tasks can be performed at the same time.

 

3. multithreading 1) Concept

Because each process has at least one thread (main thread), multiple sub-threads can be created in the main thread, and tasks in the main thread and sub-thread do not interfere with each other;

That is to say, at the same time, tasks in the main thread and sub-thread can be performed simultaneously.

 

2) Principle a. Single-core operating systems are on single-core operating systems, because only one task can be run at a time, how can we implement multithreading ??

The system will specify a specific execution time for each thread. Of course, this time is very short, and then switch (Schedule) between each thread to achieve multithreading.

 

It can be seen that the multi-thread of a Single-core operating system is actually serial, but the switching between threads takes a short time, so it looks like multithreading.

 

B. Multi-core operating system
In a multi-core operating system, multiple tasks can be run at the same time, So multithreading is easy to implement and true Multithreading

 

 

 

3) Advantages and Disadvantages. advantage can improve CPU utilization and execution efficiency B. disadvantage: memory consumption (creating a new thread will consume a certain amount of memory). If too many threads are enabled, the CPU overhead will increase.

 

4) multithreading for iOS

After the iOS application is started, only one thread (main thread, also called UI thread) is enabled)

Usually, do some time-consuming work in the main thread, such as refreshing the UI, monitoring events, etc.

Related Article

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.