You are currently viewing a snapshot of www.mozilla.org taken on April 21, 2008. Most of this content is
highly out of date (some pages haven't been updated since the project began in 1998) and exists for historical purposes only. If
there are any pages on this archive site that you think should be added back to www.mozilla.org, please file a bug.

Three Types of Event Loops

In designing this code we identified three types of event loops that
are often found in an application. The distinction/ implementation
of each may be the same across some of them for the different types depending
upon the platform, but from a conceptual point of view we came up with
three event loop types:

MainAppLoop - This is the main loop of an application. Typically
this is found at the bottom of the main. It's exit usually signals
the desire for the application to close down. There can only be one
of these per application.

ThreadLoop - This is the loop commonly found at the bottom of a
UI Thread's main procedure. The exit of this loop usually signals
the desire for the thread to quit. There can only be on of these
per thread.

AppBreathLoop - This is a loop commonly put in various places
through out the client code to allow processing of native events from some
position up the stack. In the windows world commonly implemented
using a PeekMessage loop, on other platforms it may be a yield of some
kind or actually processing/ dispatching the real main events. The
actual usage of these can be plagued with problems depending upon design
because of re-entrancy, but there are places that do legitimately need
them and thus we will provide the functionality in an XP fashion.
There can be any number of these types of loops. These also differ
from the other two loops in that loops of this kind return once it has
relinquished control to the OS and other apps for a while. Where
as the other loops run until they are complete because of a desire to exit
the loop.