Threads and Semaphores: 3.1 GEOS Multitasking: GEOS Threads

Up: GEOS SDK TechDocs | Up | Prev: 3 GEOS Multitasking | Next: 3.2 Context Switches

The various units that take turns running in the system are called "threads" in GEOS. Threads can have different priorities; a thread that has a higher priority (indicated by a lower priority number) will generally get more processor time.

Keeping Track of Threads

In order to switch among threads, the system needs to keep track of certain things about each one. For each thread, the system keeps track of priority, the most recent values of the registers, and flags. The priorities are used to determine which thread is going to run next. When the thread is run, the appropriate registers are reset to the values they had the last time the thread was stopped. This allows the thread to resume execution as though it had never been interrupted.

Like other things in GEOS, each thread has a handle, a sixteen-bit value which programs use to refer to the thread. When calling thread-related routines (e.g., to set the thread's priority), programs use the handle to specify the thread.

Event-Driven and Procedural Threads

GEOS uses two different types of threads. The two types differ only in the way they run when their turn comes and in the way they are created. The discussions about priority, context switches, and synchronization elsewhere in this chapter apply equally to both types.

The first type of GEOS thread is an "event-driven" thread. An event-driven thread normally executes code for one or more objects. Each event-driven thread has an event queue; when a message is sent to any object created by the thread, the message is placed in the thread's event queue. The thread processes each event in the order received by executing the appropriate message handler from the object's class definition.

Messages can also be sent to the thread itself rather than to an object created by the thread. When the thread is created, it is assigned a class--normally a subclass of ProcessClass (for non-application threads) or GenProcessClass (for application threads)--to determine the handlers to use when messages are sent directly to the thread. In this sense, the thread can be considered an instance of the given class.

The second type of thread is procedural. Rather than running handlers for messages in an object-oriented scheme, it simply executes procedural code.
The system does not provide an event queue for a procedural thread, and messages cannot be sent to such a thread.


Up: GEOS SDK TechDocs | Up | Prev: 3 GEOS Multitasking | Next: 3.2 Context Switches