|
|
|
|
|
|
Note: (how it is done)
|
|
|
|
|
Because:
|
|
/* --------------------------------------
Initialization step
-------------------------------------- */
1. Initialize system state variables (Events list = empty, etc)
2. Initialize (simulation) clock (usually starts at simulation time zero).
3. Schedule an initial event (i.e., put some initial event into the Events List).
/* --------------------------------------
The actual simulation....
-------------------------------------- */
While (simulation has not ended) do
{
1. Set (simulation) clock to time of the next event (advances clock)
2. Do the next event and remove the event from the Events List.
}
|
|
/* --------------------------------
Process 1
-------------------------------- */
void Proc1()
{
while (1)
{
Hold(1.2); /* Schedule a "resume" event at "Now + 1.2" */
printf("Proc1: Now = %lf\n", Now); /* Print current simulation time */
}
}
/* --------------------------------
Process 2
-------------------------------- */
void Proc2()
{
while (1)
{
Hold(1.5); /* Schedule a "resume" event at "Now + 1.5" */
printf("Proc2: Now = %lf\n", Now); /* Print current simulation time */
}
}
int main(int argc, char **argv)
{
/* -----------------------------------------------------
Initialize system variables in the simulation system
InitProsim( #Processes, # )
------------------------------------------------------ */
InitProsim(1000, 1000, 1000);
/* -----------------------------------------------------
Create process "Proc1"
------------------------------------------------------ */
Generate("Name:Proc1", Proc1, 0);
/* -----------------------------------------------------
Create process "Proc2"
------------------------------------------------------ */
Generate("Name:Proc2", Proc2, 0);
/* -----------------------------------------------------
Run the simulation for 10 "virtual" seconds
------------------------------------------------------ */
StartSimulate(10);
printf("DONE !\n");
}
|
Output of program:
Proc1: Now = 1.200000 Proc2: Now = 1.500000 Proc1: Now = 2.400000 Proc2: Now = 3.000000 Proc1: Now = 3.600000 Proc2: Now = 4.500000 Proc1: Now = 4.800000 Proc1: Now = 6.000000 Proc2: Now = 6.000000 Proc1: Now = 7.200000 Proc2: Now = 7.500000 Proc1: Now = 8.400000 Proc2: Now = 9.000000 Proc1: Now = 9.600000 Proc2: Now = 10.500000 DONE ! |
Compile with:
cc -g -O -o main1 -I /home/cs558000/lib main1.c \
-L /home/cs558000/lib -lProSim4 -lOnAbort -lm
|