Http://blog.csdn.net/dongdongdongjl/article/details/7794050
Today, I saw the nsunloop. In fact, I also read the content about the nsunloop. Here I want to briefly summarize my understanding. In fact, there are no more functions involved in the development process. In general, the nsunloop is similar to the Message Mechanism of windows. It adds an event processing mechanism to the thread.
For multi-threaded development, there are two solutions. One is to directly calculate large data content without too much interaction, another method is to add the execution function to the message loop, wait for the event to occur, and then execute it.
With the nsunloop, the thread performance will be better. An important purpose of its existence is to wake up the thread when an event occurs. When there is no event, the thread will be in sleep state, this kind of multi-threaded operation can provide excellent user performance. Because the thread actually has overhead.
For the nsunloop, the original input includes the original input and the timer. The original input is asynchronous communication, while the timer is synchronous input. The original event input is not directly defined by the user, but is implemented through some specific port object machine methods.
Run loops is part of the thread-related basic framework. A run loop is a loop of event processing. It is used to schedule tasks and process input events without interruption. The purpose of running loop is to make your thread busy at work and sleep when it is not at work.
Run loops is part of the thread-related basic framework. A run loop is a loop of event processing. It is used to schedule tasks and process input events without interruption. The purpose of running loop is to make your thread busy at work and sleep when it is not at work.
When to use runloop
3.2 When to use run Loop
You only need to run a run loop explicitly when creating a secondary thread for your program. Run loop is a key part of the main thread infrastructure of the program. Therefore, the cocoa and carbon programs provide code to run the cycle of the main program and automatically start the run loop. In iOS, the run method of uiapplication (or nsapplication in Mac OS X) is part of the program startup step. It starts the main loop of the program when the program starts normally. Similarly, the runapplicationeventloop function starts the main loop for the carbon program. If you use
The template provided by xcode creates your program, so you never need to explicitly call these routines on your own.
For auxiliary threads, You need to determine whether a run loop is required. If required, configure and start it on your own. You do not need to start the run loop of a thread in any situation. For example, when you use a thread to process a pre-defined long-running task, you should avoid starting the run loop. Run loop is required only when you need more interaction with the thread, for example:
Use a port or custom Input Source to communicate with other threads. Use the timer cocoa of the thread to use any performselector... method to make the thread work cyclically.
2011-11-28 | 2011 youmi mobile Co. Ltd. All Rights Reserved. [33] threading programming guide
If you decide to use the run loop in the program, it is easy to configure and start. Like all Thread Programming, you need to plan the situation where the auxiliary thread exits the thread. It is better to enable the thread to exit naturally than to disable it forcibly. For more information about how to configure and exit a run loop, see "use run loop object.