Multithreading and scratch
What is a process before learning multithreading?
A process is an application running in the system.
Each process is independent, and each process runs in its dedicated and protected memory space.
You can use the "activity monitor" to view the processes enabled in Mac.
What is thread next?
To execute a task, a process must have a thread (each process only needs one main thread)
All tasks in a process are executed in the thread.
Thread serial
1. Serial
2. If you want to execute multiple tasks in one thread, you can only execute them one by one in order.
So what is multithreading?
1. Multiple Threads can be opened in a process, and each thread can execute different tasks in parallel.
2. multithreading technology can improve program execution efficiency
Multithreading Principle
1. At the same time, the CPU can only process one thread, and only one thread is working.
2. Concurrent execution of multiple threads means that the CPU is switching quickly.
3. Because CPU switching is fast, multithreading is caused (in fact, it is an illusion)
Advantages and disadvantages of Multithreading
Advantages:
1. Improve program execution efficiency
2. appropriately improving resource utilization
Disadvantages:
1. There is an overhead for creating a thread. It takes about 90 milliseconds to create a thread in iOS.
2. Enabling a large number of threads will reduce program performance.
3. Make the program design more complex