Are there any possible way to create two or more run loop in one thread? Or one thread can have only one run loop?
My partner tells me, one thread is possible to have two or more run loop inside. And I doubt it. I had googled but found nothing. So, is it possible to have two or more run loop in one thread ?
Overview. A RunLoop object processes input for sources, such as mouse and keyboard events from the window system and Port objects. A RunLoop object also processes Timer events. Your application neither creates nor explicitly manages RunLoop objects.
A CFRunLoop object monitors sources of input to a task and dispatches control when they become ready for processing. Examples of input sources might include user input devices, network connections, periodic or time-delayed events, and asynchronous callbacks.
Threads are especially useful when you need to perform a lengthy task, but don't want it to block the execution of the rest of the application. In particular, you can use threads to avoid blocking the main thread of the application, which handles user interface and event-related actions.
From Apple's documentation on NSRunLoop:
Your application cannot either create or explicitly manage NSRunLoop objects. Each NSThread object, including the application’s main thread, has an NSRunLoop object automatically created for it as needed.
Beyond that, I see no reason why you'd want to create more than one runloop per thread.
I would like to add this quote from CFRunLoop Reference documentation
There is exactly one run loop per thread. You neither create nor destroy a thread’s run loop. Core Foundation automatically creates it for you as needed.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With