Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have more than one runloop per thread on iOS?

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 ?

like image 523
AechoLiu Avatar asked Aug 23 '11 08:08

AechoLiu


People also ask

What is IOS RunLoop?

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.

What is Cfrunlooprun?

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.

What is thread in Swift?

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.


2 Answers

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.

like image 74
Brad Larson Avatar answered Oct 02 '22 07:10

Brad Larson


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.

like image 44
Gabriele Avatar answered Oct 02 '22 08:10

Gabriele