Where multiple asynchronous services are used by a program, a wait loop is required.
The CActiveScheduler
class encapsulates the wait
loop.
Nearly all threads use an active scheduler. Low-level test programs may have to construct their own active scheduler, but all server threads and all UI programs, have an active scheduler after they have initialised. If an active scheduler is present, active objects may be added to it and removed from it at will.
A thread may not have more than one active scheduler.
Together with active objects, the active scheduler provides a system of non-pre-emptive multi-processing which runs in a single thread. In conventional systems, multi-processing is often done using multiple threads.
In EPOC, it is easier to write a system of co-operating active objects than a system of co-operating threads. The run-time cost of an active object is also significantly less than that of a thread. Creating and destroying active objects is very much more efficient than creating and destroying threads.
When the active scheduler executes its wait loop, the order in which active objects are tested for scheduling is determined by their relative priorities. Most active objects should have a priority of zero and there should be an assumption that their relative position in the queue is irrelevant. No processing should ever depend on the order in which active objects are scheduled.