process

What is a process

Process refers to an application program that is running in the system. Each process is independent and runs in its dedicated and protected memory space. For example, when thunderbolt and Xcode are opened at the same time, the system will start two processes respectively

Thread What is a thread in order for a process to execute a task, it must have a thread (each process must have at least one thread). All tasks of a process (program) are executed in the thread, such as playing music with cool dog, downloading movies with thunderbolt, all need to be executed in the thread

Threads of serial task in one thread is serialized If you want to perform multiple tasks in a thread, then only one by one in order to perform these tasks That is to say, at the same time, a thread to perform only one task As in A thread download three files (files, files, B, C)

1. A thread is the smallest unit of CPU invocation (performing a task).

2. A process is the unit of CPU resource allocation and scheduling.

3. A program can correspond to multiple processes. A process can have multiple threads, but there must be at least one thread.

4. Threads in the same process share process resources.

multithreading

1 what is a multithreaded process can open multiple threads, each thread can parallel process (and) perform different tasks a workshop, thread a workshop worker multithreading technology can improve the efficiency of the execution of the program For example, at the same time open three threads respectively download three files (files, files, B, C)

The principle of multi-threaded multi-threaded principle At the same time, the CPU can only handle one thread, only one thread at work (execute) multi-threaded concurrent () at the same time, in fact is the CPU rapidly between the multiple thread scheduling (switch) if the CPU thread scheduling time fast enough, creates a multi-threaded concurrent execution the illusion of thinking: What happens if there are very, very many threads? The CPU will be scheduled between N threads, and the CPU will be exhausted and consume a large amount of CPU resources. The execution frequency of each thread will be reduced (the execution efficiency of the thread will be reduced).

Advantages and disadvantages of multi-threading

The advantage of multi-threading is that it can properly improve the execution efficiency of the program and properly improve the resource utilization (CPU, memory utilization).

Disadvantages of multithreading There are costs associated with creating threads. The main costs under iOS include: -setStackSize: set, but must be a multiple of 4K, and the minimum is 16K. It takes about 90 milliseconds to create a thread. The more CPU overhead it takes to schedule threads, the more complex the programming becomes: communication between threads, data sharing between multiple threads

What is the main thread in iOS development? By default, when an iOS application is running, one thread is opened, which is called the “main thread” or “UI thread”.

Handle UI events (click events, scroll events, drag events, etc.)

Use of the main thread. Do not put time-consuming operations into the main thread. Time-consuming operations will block the main thread, seriously affect the UI smoothness, and give users a bad experience of “stuck”