PROCESSES

Processes represent the active entities in a CSIM model. For example, in a model of a bank, customers might be modeled as processes (and tellers as facilities). In CSIM, a process is a C (or C++) procedure which executes a create statement. A CSIM process should not be confused with a UNIX process (which is an entirely different thing). The create statement is similar to a UNIX “fork" statement. A process can be invoked with input arguments, but it cannot return a value to the invoking process. There can be several simultaneously "active" instances of the same process. Each of these instances appears to be executing in parallel (in simulated time) even though they are in fact executing sequentially on a single processor. The CSIM runtime package guarantees that each instance of every process has its own runtime environment. This environment includes local (automatic) variables and input arguments. All processes have access to the global variables of a program.

A CSIM process, just like a real process, can be in one of four states:

  • Actively computing
  • Ready to begin computing
  • Holding (allowing simulated time to pass)
  • Waiting for an event to happen (or a facility to become available, etc.)

    When an instance of a process terminates, either explicitly or via a procedure exit, it is deleted from the CSIM system. Each process has a unique process id and each has a priority associated with it.

    Initiating a Process

    To initiate a process:
    proc(arg1, ..., argn);
    proc_id = proc(arg1,...,argn);
    Where:

  • proc - is the name of the process to be initiated (as with a procedure call or function invocation in C)
  • arg1-argn - are any arguments to be passed. Don’t pass parameters which are addresses of variables local to the initiating process (e.g., local arrays) because when the initiated process is executing, the initiating process will be suspended and the addresses could be invalid.
  • proc_id - is the process id of the new instance of the initiated process (type long)

    Notes:

  • A process cannot return a function value.
  • A create() statement (see below) must appear in the initiated process.

    To create a process:
    create("name");
    Where:

  • name - is the name of the process instance being created (quoted string or type char*)

    Notes:

  • When executed within a procedure, create establishes that procedure as a CSIM process with the given name.
  • The create statement will normally be the first executable statement in the body of each process description.

    Notes:

  • Each process is given a unique process id (process id's are not reused).
  • Processes can invoke procedures and functions in any manner.
  • Processes can initiate other processes.

    Terminating a Process

    A process terminates when it either executes a terminate statement or when it does a normal procedure exit. To explicitly terminate a process:
    terminate();
    Notes:

  • A terminate statement is not required if the process (procedure) exits normally (either executes a return statement or "flows" out of the procedure).

    Indicating Process Priority

    The initial priority of a process is inherited from the initiator of that process. For the sim (main) process, the default priority is 1 (low priority).

    To change the priority of a process:
    set_priority(p);
    Where:

  • p - is the priority to which the process is to be set (type long). Notes:
  • This statement must appear after the create for its process.
  • Lower numbers represent lower priorities (i.e. priority 1 processes will run later than priority 2 processes when priority is a consideration in order of execution (see “ Service Disciplines” on page 9).

    Retrieving Process-Related Information

    These functions each return some information the process issuing the statement. The type of the returned value for each of these functions is as indicated. The syntax conventions for these statements are as follows:
    a - is a returned value of type char*.
    n is a returned value of type long.

    Retrieving Static Process Information

    Statement			 Returned Value
    
    a = process_name();		pointer to name of process issuing inquiry
    n = identity();			identifier (process number) of process issuing inquiry
    n = priority();			priority of process issuing inquiry
    

    Reporting Process Status

    To print the status each active process in a model:
    status_processes();
    Notes:

  • This report lists each active process, along with its:
  • State
  • Priority
  • Process class membership
  • The report will be written to the default output location or to that specified by set_output_file

    To print the status of processes with pending state changes (the “next evet list)
    Notes:

  • This report lists each process which is currently in the next event list along with:
  • Its index in the event list
  • The time the event is supposed to occur
  • The event type
  • The report will be written to the default output location or to that specified by set_output_file