Simulation using Processes

by Lin Jensen, Bishop's University

written in Turbo Pascal 6.0 or 7.0

The simulation toolboxes provide processes in the
units: COPROC, PROC_MAN, (and MESSAGE)

Topics:

A Process is an object with its own thread of control. i.e. a CO-ROUTINE

Processes run "concurrently", on a conventional processor this means that control is swapped between them. In a simulation, processes persist over time, with their actions interleaved.

A process may be in these states:


HERE IS WHAT PROCESSES CAN DO:


HOW TO DEFINE A PROCESS:

  1. Create a process class as follows:
    TYPE
        GIANTptr = ^ GIANT;
        GIANT    = OBJECT (procdescr)
           field1:  )
           .....    )  Globally accessible variables of this process type
           fieldN:  )
          constructor init (name:pname, index:integer, ..[specific inits] ) ;
            {--- OPTIONAL may beef up standard init --
             IF SO, MUST CALL ProcDescr.Init (name, index) !!}
          procedure lifecycle; VIRTUAL;   {MUST define a life cycle}
              [ other special methods ]
        end; 
    
    The minimum requirement is:
            Giant = object (procdescr)
                procedure lifecycle; VIRTUAL;
            end;
    
  2. Define the process' life cycle as a procedure:
            procedure GIANT.LifeCycle;
            var
               [any private local variables]
            begin
               [do this ...]
               ....
               [... do that]
            end; 
    
    {processes may exhaust life cycle, in which case they terminate themselves, and are removed by the monitor}
  3. Create instances, and initialize, using NEW and Init:
        VAR
             bigboy : GiantPtr;
    
        NEW (bigboy, init('Rumble-Buffin', 42, ... ));        
        RESUME (bigboy);        { to put on ready queue }
    

HOW the "MONITOR" WORKS:

A simulation starts (or continues), after at least one process has been created and resumed (made ready), by a call to
       Monitor.RunSimulation (time_to_simulate, number_of_samples)
The monitor maintains 3 queues: ready, deferred, and sleep. The first process on the ready queue starts running. When a context switch is called for (by one of the above mechanisms), the monitor switches context to either:
  1. the main program, If the simulation time or number of samples has expired, or
  2. the first process on the ready queue, or if none,
  3. the first process on the sleep queue, and
    • advances the clock to its time, and
    • puts the deferred processes on the ready queue.

Is this DISCRETE OR CONTINUOUS simulation?

Well, The choice is yours, combined simulation is a snap!
Last updated 17 October 1996

Up to top of this document
Back to Simulation notes. home arrow

Comments, etc, send to

ljensenn at ubishops.ca