Thread Overview
For example, if Hello World is run and printed, its life cycle ends. Some programs are a circle that keeps repeating until it is cut off, such as the operating system, until you shut down.
Create thread
[myObj performSelectorInBackground:@selector(doSomething) withObject:nil];
Multithreading
The thread application in the iPhone is not uncontrolled. Official documents show that the stack size of the main thread in the iPhone OS is 1 MB, and that of the second thread is kb at the beginning. The value cannot be changed through the compiler switch or the thread API function. Only the main thread can directly modify the UI.
- ()setMaxConcurrentOperationCount:(NSInteger)count
Inter-thread Communication
1. datagmselect On The Thread
RunLoop
There are two types of events to be processed: one is the input source and the other is the timer.,Input SourceTransmits asynchronous events. messages are generally sent from other threads or programs.Scheduled sources are the operations that require scheduled execution,Transfer a synchronization event at a specific time or repetition interval. Both origins use a specific processing routine of the program to process events that arrive.There are three types of input sources: performSelector source, Mach port-based source, and custom source.You can add your own source when programming. RunLoop also has the concept of Observer. You can add your own Observer to RunLoop to monitor the running process of RunLoop.
By default, RunLoop of non-main threads does not run. You need to add at least one event source for RunLoop.And then run it. Generally, we do not need to enable the RunLoop of a thread unless you need to detect an event for a long time in a separate thread.