home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / xc212os2.zip / ISODEF / processe.def < prev    next >
Text File  |  1994-12-22  |  5KB  |  121 lines

  1. DEFINITION MODULE Processes;
  2.  
  3.   (* This module allows concurrent algorithms to be expressed using processes.  A process is
  4.      a unit of a program that has the potential to run in parallel with other processes.
  5.   *)
  6.  
  7. IMPORT SYSTEM;
  8.  
  9. TYPE    
  10.   ProcessId;                      (* Used to identify processes *)
  11.   Parameter     = SYSTEM.ADDRESS; (* Used to pass data between processes *)
  12.   Body          = PROC;           (* Used as the type of a process body *)
  13.   Urgency       = INTEGER;        (* Used by the internal scheduler *)
  14.   Sources       = CARDINAL;       (* Used to identify event sources *)
  15.   ProcessesExceptions =           (* Exceptions raised by this module *)
  16.     (passiveProgram, processError);
  17.  
  18. (* The following procedures create processes and switch control between them. *)
  19.  
  20. PROCEDURE Create (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency;
  21.                   procParams: Parameter; VAR procId: ProcessId);
  22.   (* Creates a new process with procBody as its body, and with urgency and parameters
  23.      given by procUrg and procParams.  At least as much workspace (in units of
  24.      SYSTEM.LOC) as is specified by extraSpace is allocated to the process.
  25.      An identity for the new process is returned in procId.
  26.      The process is created in the passive state; it will not run until activated.
  27.   *)
  28.  
  29. PROCEDURE Start (procBody: Body; extraSpace: CARDINAL; procUrg: Urgency;
  30.                  procParams: Parameter; VAR procId: ProcessId);
  31.   (* Creates a new process, with parameters as for Create.
  32.      The process is created in the ready state; it is eligible to run immediately.
  33.   *)
  34.  
  35. PROCEDURE StopMe ();
  36.   (* Terminates the calling process.
  37.      The process must not be associated with a source of events.
  38.   *)
  39.  
  40. PROCEDURE SuspendMe ();
  41.   (* Causes the calling process to enter the passive state.  The procedure only returns
  42.      when the calling process is again activated by another process.
  43.   *)
  44.  
  45. PROCEDURE Activate (procId: ProcessId);
  46.   (* Causes the process identified by procId to enter the ready state, and thus to become
  47.      eligible to run again.
  48.   *)
  49.  
  50. PROCEDURE SuspendMeAndActivate (procId: ProcessId);
  51.   (* Executes an atomic sequence of SuspendMe() and Activate(procId). *)
  52.  
  53. PROCEDURE Switch (procId: ProcessId; VAR info: Parameter);
  54.   (* Causes the calling process to enter the passive state; the process identified by procId
  55.      becomes the currently executing process.
  56.      info is used to pass parameter information from the calling to the activated process.
  57.      On return, info will contain information from the process that chooses to switch back to
  58.      this one (or will be NIL if Activate or SuspendMeAndActivate are used instead of
  59.      Switch).
  60.   *)
  61.  
  62. PROCEDURE Wait ();
  63.   (* Causes the calling process to enter the waiting state.  The procedure will return when
  64.      the calling process is activated by another process, or when one of its associated
  65.      eventSources has generated an event.
  66.   *)
  67.  
  68. (* The following procedures allow the association of processes with sources of external
  69.    events.
  70. *)
  71.  
  72. PROCEDURE Attach (eventSource: Sources);
  73.   (* Associates the specified eventSource with the calling process. *)
  74.  
  75. PROCEDURE Detach (eventSource: Sources);
  76.   (* Dissociates the specified eventSource from the program. *)
  77.  
  78. PROCEDURE IsAttached (eventSource: Sources): BOOLEAN;
  79.   (* Returns TRUE if and only if the specified eventSource is currently associated with
  80.      one of the processes of the program.
  81.   *)
  82.  
  83. PROCEDURE Handler (eventSource: Sources): ProcessId;
  84.   (* Returns the identity of the process, if any, that is associated with the specified
  85.      eventSource.
  86.   *)
  87.  
  88. (* The following procedures allow processes to obtain their identity, parameters, and
  89.    urgency.
  90. *)
  91.  
  92. PROCEDURE Me (): ProcessId;
  93.   (* Returns the identity of the calling process (as assigned when the process was first
  94.      created).
  95.   *)
  96.  
  97. PROCEDURE MyParam (): Parameter;
  98.   (* Returns the value specified as procParams when the calling process was created. *)
  99.  
  100. PROCEDURE UrgencyOf (procId: ProcessId): Urgency;
  101.   (* Returns the urgency established when the process identified by procId was first
  102.      created.
  103.   *)
  104.  
  105. (* The following procedure provides facilities for exception handlers. *)
  106.  
  107. PROCEDURE ProcessesException (): ProcessesExceptions;
  108.   (* If the current coroutine is in the exceptional execution state because of the raising
  109.      of a language exception, returns the corresponding enumeration value, and
  110.      otherwise raises an exception.
  111.   *)
  112.  
  113. PROCEDURE IsProcessesException (): BOOLEAN;
  114.   (* Returns TRUE if the current coroutine is in the exceptional execution state
  115.      because of the raising of an exception in a routine from this module; otherwise
  116.      returns FALSE.
  117.   *)
  118.  
  119. END Processes.
  120.  
  121.