Second try on how to understand run loops

493 views Asked by At

Possible Duplicate:
How a runloop actually works

Hi

I have asked these two questions earlier, but yet I do not understand it.

Question about Runloops 1
Question about Runloops 2

In one of my iPhone-books they mention the run loop as this:

”Your application is one giant infinite loop called the run loop. The run loop’s job is to check for input (a touch, Core Location updates, data coming through a network interface, etc.) and find the appropriate handlers for that event (like an action or delegate method for an object).”

Okey, so where exactly is the loop? I know that the main application thread don’t need to run it and every thread has an associated run loop object however where is the actual loop portion of it? Is it a while loop that invisible surrounds the main-method, and if it where a loop that was looping wouldn’t that loop all of my code. I understand that this is wrong and it is not done though.

I do not understand the different modes a runloop can run in either, but maybe it is because I do not understand the runloop.

Thanks in advance!

1

There are 1 answers

1
Bogatyr On

Take a look at the typical "main()" function for an iPhone (or any Cocoa, but Cocoa proper uses NSApplicationMain instead of UIApplicationMain) application:

#import <UIKit/UIKit.h>

int main(int argc, char *argv[]) {

    NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
    int retVal = UIApplicationMain(argc, argv, nil, nil);
    [pool release];
    return retVal;
}

This is the entire application, there is nothing unusual or "wrapped around" this main() routine. So, logically, you can conclude that the run loop is contained within the call to UIApplicationMain.