Important: The information in this document is superseded by the information in Threading Programming Guide. For information about how to configure a run loop for your custom threads, see that document instead.
Using Run Loops With Cocoa and Carbon
Cocoa and Carbon each build upon CFRunLoop to implement their own higher-level event loop. Cocoa exposes its event loop through the NSApplication and NSRunLoop classes; Carbon exposes its event loop through the Carbon Event Manager.
When writing a Cocoa or Carbon application, you can add your sources, timers, and observers to their run loops and modes. Your objects will then get monitored as part of the regular application event loop. Use the NSRunLoop instance method
getCFRunLoop to obtain the CFRunLoop corresponding to a Cocoa run loop. In Carbon applications, use the
Cocoa and Carbon automatically set up and run the run loop in the main thread of the application. If you spawn additional threads, you are responsible for managing and running their run loops.
Cocoa defines several of its own run loop modes for use with NSRunLoop objects. Cocoa defines
NSDefaultRunLoopMode as its default run loop mode, but this is equivalent to Core Foundation’s
kCFRunLoopDefaultMode and can be used interchangeably. Cocoa also defines the modes
NSEventTrackingRunLoopMode in which it runs the main thread’s run loop when a modal panel is up or during event-tracking operations, such as drag-and-drop operations, respectively. Both of these modes are members of the main thread’s set of common modes.