|
Go backward to Node: Network NodesGo up to 4.1 Types Go forward to Selector: Message Selectors |
|
Scheduler: Program Schedulers
abstract class Scheduler
{
int getNumber()
boolean isReady(int i)
int incTime();
abstract int nextProgram()
}
A scheduler selects the next program for execution among those node programs
that are in the ready state. A scheduler must redefine the abstract
function nextProgram() such that this function returns some i
with 0 <= i < getNumber() and isReady(i)
(i.e. it must select one ready node program for execution). If this condition
cannot be fulfilled, the scheduler must return -1 (denoting deadlock). The
scheduler should call incTime() on each attempt to select a (possibly
non-ready) program for execution; this will increase the global network time
in the upper left corner of the visualization window.
The default scheduler selects in a round robin mechanism the next program ready for execution; it is an object of type
class SchedulerDefault extends Scheduler
{
int last = -1;
int nextProgram()
{
int n = getNumber();
boolean reset = false;
do
{
incTime();
last++;
if (last == n)
{
last = 0;
if (reset) return -1;
reset = true;
}
}
while (!isReady(last));
return last;
}
}
The default scheduler may be redefined to implement different kinds of network models (synchronized networks, asynchronous networks, ...).