OMThread class

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:

Attribute summary
aomthread - specifies the "instrumented" part of the thread
endOfProcess - specifies whether the application is at the end of a process
eventQueue - specifies the thread's event queue
thread - specifies the "os" part of the thread
toGuardThread - determines whether a section of thread code will be protected
Construction summary
OMThread
Constructs an OMThread object
~OMThread
Destroys the OMThread object
Method summary
allowDeleteInThreadsCleanup
Postpones the destruction of a framework thread until the application terminates and all user threads are deleted
cancelEvent
Marks a single event as canceled (that is, it changes the event's ID to Constants)
cancelEvents
Marks all events targeted for the specified OMReactive instance as canceled (that is, it changes the events' IDs to Constants)
cleanupAllThreads
Kills" all threads in an application except for the main thread and the thread running the cleanupAllThreads method
cleanupThread
Provides a "hook" to allow a thread to be cleaned up without a call to the DTOR
destroyThread
Destroys the default active class or object for the framework
doExecute
Is the entry point to the thread main loop function
execute
Is the thread main loop function
getAOMThread
Is used by the framework for animation purposes
getEventQueue
Is used by the framework for animation purposes
getGuard
Gets the reference to the OMProtected part
getOsHandle
Returns the thread's operating system ID
getOSThreadEndClb
Requests a callback to end the current operating system thread
getStepper
Is used by the framework for animation purposes
lock
Puts a lock on the thread mutex
omGetEventQueue
Returns the event queue
queue
Queues events to be processed by the thread event loop (execute)
resume
Resumes a thread suspended by the suspend method
schedTm
Creates a timeout request and delegates the request to OMTimerManager
setEndOSThreadInDtor
Specifies whether an operating system thread in destruction is deleted
setPriority
Sets the priority of the thread being executed
setToGuardThread
Sets the toGuardThread flag
shouldGuardThread
Determines whether the thread is guarded
start
Activates the thread to start its event-processing loop
stopAllThreads
Is used to support the DLL version of the Rational® Rhapsody® Developer for C++ execution framework (COM)
suspend
Suspends the thread
unlock
Unlocks the thread mutex
unschedTm
Cancels a timeout request
Attributes and flags

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.


Feedback