IOS uses multithreading to improve performance, and ios multithreading to improve performance
The iPhone will be able to support different types of multi-threaded APIs, including POSIX Threads, NSObject, NSThread, and NSOperation.
The iPhone operating system is a real preemptible, multi-task operating system that allows developers to create multi-threaded applications.
When I hold an iPhone, I actually have a preemptible, Multitasking Computer with a Unix operating system. It has a graphical interface and provides GPS functions, wi-Fi and a large number of built-in function libraries. This is also a mobile phone, which is amazing!
A thread or execution thread is a branch of a computer program, which can lead to two or more concurrent tasks. Threads are included in computer programs.
Basically, if the application needs to ensure user responsiveness while completing one or more tasks, multithreading should be used for the application.
Multithreading means that the operating system controls multiple processes to share the CPU time and waits for their time slice to arrive to achieve the simultaneous running of multiple tasks. The operating system will let the CPU serve a process for several milliseconds, and then require the process to enter the sleep state, and let the CPU provide services for other processes.
A process is a running application.
If multiple threads attempt to access resources and complete read and write operations at the same time, the resource value may be incorrect and may be damaged. For example, assume that two threads represent two roles in a game application, and the two threads run simultaneously. Synchronization means to maintain data consistency or data integrity between threads. If one thread tries to read the gameScroe variable while the other thread tries to update the gameScore variable, the gameScore variable may be incorrect.
The critical section is a piece of code that can protect shared resources and prevent multiple threads from simultaneously accessing this code and undermining shared resources.
When some conditions exist, the time sequence of threads accessing resources may lead to unexpected results. This situation is usually called a race condition.
Mutex lock in multiple threads is used to avoid using a public resource at the same time. Many well-known examples of competitive conditions have led to disastrous consequences.
Two or more threads are always blocked. When each other waits for the other party to release their unique resources, another common trap in the thread application will appear. This is called a deadlock condition.
When a thread is started, it is actually out of the Cocoa framework. In this case, we are responsible for clearing the memory pool. If this is not done, memory leakage will occur.
The running loop will process the events that you use to schedule the work, and coordinate the arrival of events. Its function is to keep the thread busy during work, when there is no work, set the thread to sleep mode. Learn more about running cycles.