SSim C++ API documentation (v. 1.7.6)
Classes | Public Member Functions | Static Public Member Functions | Static Public Attributes | List of all members
ssim::TProcess Class Reference

Virtual class representing sequential processes. More...

#include <tprocess.h>

Inheritance diagram for ssim::TProcess:
ssim::Process

Classes

class  Timeout
 timeout event More...

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.
- Public Member Functions inherited from ssim::Process
virtual void init (void)
 action executed when the process is initialized.
virtual void process_event (const Event *msg)
 action executed in response to an event signaled to this process.
virtual void stop (void)
 executed when the process is explicitly stopped.

Static Public Member Functions

static const Eventwait_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.

Detailed Description

Virtual class representing sequential processes.

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.

See Also
Process
Examples:
bstp.cc, and tp.cc.

Constructor & Destructor Documentation

ssim::TProcess::TProcess ( )

creates a sequential process with the default stack size.

See Also
DefaultStackSize

Member Function Documentation

virtual void ssim::TProcess::main ( )
pure virtual

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.

Examples:
tp.cc.
static const Event* ssim::TProcess::wait_for_event ( Time  timeout = INIT_TIME)
static

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;
} else {
cout << "I'm getting confusing signals here..." << endl;
}
}
};

Member Data Documentation

unsigned long ssim::TProcess::DefaultStackSize
static

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.


The documentation for this class was generated from the following file: