#include <tprocess.h>
Inheritance diagram for ssim::TProcess:
Public Member Functions | |
TProcess () | |
creates a sequential process with the default stack size. | |
TProcess (unsigned long stacksize) | |
creates a sequential process with the given stack size. | |
virtual void | main ()=0 |
body of this simulated sequential process. | |
Static Public Member Functions | |
static const Event * | wait_for_event (Time timeout=INIT_TIME) |
accepts an event over a given interval. | |
Static Public Attributes | |
static unsigned long | DefaultStackSize |
default stack size for sequential processes. | |
Classes | |
class | Timeout |
timeout event More... |
A simulated sequential process extends this class by implementing a main() method. The fundamental difference between the base Process and a TProcess is that a Process is implemented as a reactive object, that implements an algorithm by implementing reactions to incoming events in the form of callback functions. Conversely, a TProcess is a sequential process that implements an algorithm by simply implementing a main() function.
The tp.cc example illustrates the use of sequential processes.
|
creates a sequential process with the default stack size.
|
|
body of this simulated sequential process. Body of this process. This process may interact with other processes by receiving and sending signals (a.k.a., events). The passage of time in this main body can be controlled through the advance_delay method.
|
|
accepts an event over a given interval. This method suspends the execution of the current process until either an event is signaled to the current process or the given timeout expires. A (default) timeout value of INIT_TIME means an infinite timeout. If an event is signaled before the timeout expires, this method returns that event. If the timeout expires before any event is received, this method returns a Timeout event. This method must be called within the execution of the main() method of a TProcess. The following example illustrates a typical way to use this method:
class HaveFork : public Event { //... }; class Philosopher : public TProcess { //... virtual void main() { cout << "I'll see if a fork becomes available" << endl; // const Event * e = wait_for_event(100); if (dynamic_cast<const HaveFork *>(e) != 0) { cout << "I got one, I'll start eating now..." << endl; // ... } else if (dynamic_cast<const TProcess::Timeout *>(e) != 0) { cout << "I got tired of waiting!" << endl; // ... cout << "I'll go to sleep now" << endl; cout << "Somebody must send me a signal to wake me up" << endl; wait_for_event(); } else { cout << "I'm getting confusing signals here..." << endl; } } };
|
|
default stack size for sequential processes. The initial value is 8Kb. This value can be dynamically adjusted, and will affect all newly created TProcess objects. |