OMThread is a framework base active class. Its responsibilities are as follows:
This class is defined in the header file omthread.h.
OMThread is a base class for every class that is active. An object of an active class:
Therefore, every active object has an OMThread instance, which is composed of two things:
By default, there are at least two threads in an application: the timer thread and the main thread. In this simple case, all events are queued in the main thread event queue.
Every operating system has a different implementation of a native thread.
The thread is responsible for providing event services to all instances running on it. Every event that is assigned to an object is sent to its relevant thread. The thread stores the events in an event queue. OMThread uses a while loop to consume events as they appear at the front of the queue.
An active object can also serve a nonactive object. For example, your application might have a class a that has a statechart but is also active, so it inherits from OMThread and OMReactive. Your application might also have a class p that has a statechart, but is not active. Class p inherits from OMReactive.
Suppose that p is running under a's thread. Every event that is targeted for p must be stored somewhere, and p does not have an event queue. Therefore, p delegates events destined for it to a's event queue, because p is running on a's operating system thread and a has an event queue.
If you have the following line of code, generating an event e to class p, e is stored inside a's OMThread event queue:
p -> GEN(e)
In OMThread, the execute method cycles through the event queue looking for more events. When it finds one or more events, it pops the first event (for example, e) from the event queue. The event has a field specifying the destination (p, in this example). p is then notified that it should react to event e. The event is not necessarily consumed immediately - it waits in the event queue. When the time arrives for the event to be consumed, it is popped from the event queue and injected into p's OMReactive using the takeEvent method.
In Version 4.0, the inheritance from OMProtected was replaced with aggregation. As a result, the following were added to the OMThread interface:
aomthread
This protected attribute specifies the "instrumented" part of the thread.
It is defined as follows:
AOMThread *aomthread;
The AOMThread class is defined in the animation framework in the instrumented application, and set to an empty class in non-instrumented mode.
endOfProcess
This public attribute specifies whether the application is at the end of a process. If it is, the last thread in the process must "clean up."
The possible values for this flag are as follows:
It is defined as follows:
static int endOfProcess;
eventQueue
This protected attribute specifies the thread's event queue.
It is defined as follows:
OMEventQueue *eventQueue;
The class OMEventQueue is defined in os.h.
thread
This protected attribute specifies the "os" part of the thread.
It is defined as follows:
OMOSThread *thread;
The OMOSThread class is defined in os.h.
toGuardThread
This protected attribute determines whether a section of thread code will be protected. If it is set to TRUE, the code is protected. Otherwise, the code is not protected.
It is defined as follows:
OMBoolean toGuardThread;
OMBoolean is defined in rawtypes.h.
toGuardThread is checked by the execute method before it starts its event loop iteration. If toGuardThread is TRUE, execute calls the OMGuard class and the OMGuard class macros.