Most modern operating systems, including iOS, support the concept of thread execution. Each process can contain multiple threads, and they can run concurrently. If there is only one processor core, the operating system switches between all the execution threads, much like switching between all the execution threads. If you have multiple cores (cores), the threads will be dispersed across multiple cores like a process.
All threads in a process share executable program code and global data. Each thread can also have some unique data. A thread can use a special structure that becomes a mutex or a lock, which ensures that a particular block of code cannot be executed at a time without multiple threads. When multiple threads access the same data at the same time, this helps to ensure the correct results, locking other threads when one thread updates a value (called a critical section in code).
We typically focus on thread safety (THREAD-SAFE) issues while processing threads. Some repositories consider thread concurrency when they are written, and use mutexes to properly protect all their critical sections. There are also some code libraries that are not thread-safe.
For example,in iOS Cocoa Touch, the foundation framework (which contains basic classes for all OBJECT-C programming types, such as NSString, Nsarray, and so on) is generally considered thread-safe . However, theUikit framework (including classes that specialize in building GUI applications, such as UIApplication, UIView, and all of its subclasses) is non-thread-safe . This means that in a running iOS app, all method calls that process any Uikit object should be executed from the same thread, which is called the main thread-mainthread. If you access the Uikit object from another thread, the result is a lot of unexpected results (errors)! -- So the update UI runs on the main thread.
By default, the main thread performs all the actions of the iOS app (such as handling user time-triggered actions), so there is nothing to worry about for a simple application, and the user-triggered action is already (the default) running in the main thread.
IOS Multithreading-Threading Basics