home *** CD-ROM | disk | FTP | other *** search
-
- Documentation For PS.A86
-
- Process Spawning Example
-
-
- The program PS is an example of how to spawn processes and have
- them run simultaneously under Concurrent CP/M. This example
- simulates a situation where there are four external "devices"
- that are each monitored and controlled by independent processes.
- These processes continually report their status to another
- process, which displays the combined statuses on the screen. In
- this case, the only status that is being monitored is whether the
- "device" is "on" or "off".
-
- This example uses the P_CREATE function to create the sub-
- processes that will monitor the external devices. The P_CREATE
- function allows a programmer to create processes dynamically by
- defining what the initial value of all of the registers are for
- the new process, and then placing this process on the ready list.
- Using this technique, this example will create 4 processes, each
- with the same initial CS and DS values, but with different stack
- areas. This means that each of these processes will be executing
- the exact same piece of code, but since each process will use a
- separate stack area, no conflicts will arise. When a program
- uses the P_CREATE function, it must first set up a valid Process
- Descriptor (PD) and a User Data Area (UDA) for each process that
- it will create. See the CCP/M Programmer's Guide for detailed
- information about these two structures.
-
- The main process is initiated by executing the program PS from
- the console. PS.CMD is created by running PS.A86 through RASM86
- and LINK86. No special parameters are necessary for either of
- these utilities when assembling PS. The main process first
- initializes the PD and UDA for each of the sub-processes. The
- UDA's have been initialized so that each has the same code and
- data segments. All of the other registers except BX are
- initialized to zero. Register BX is initialized to the number of
- the sub-process. Since there are four sub-processes, this value
- will range from 0 to 3. The Process Descriptors are all linked
- by the Link field of the PD, so only one P_CREATE call is needed.
- Once the P_CREATE call is made, the initial (main) process prints
- the signon message, and then loops printing the status of each of
- the "devices".
-
- Since the four sub-processes simulate the "on/off" status of some
- external device, they all need to be able to communicate this
- information to the main process. Because all five processes
- share the same data area, it is easy to pass information from one
- process to another. This is done by setting up a "status line"
- area in the data segment. This status line is continually being
- printed by the main process, while each of the sub-processes
- toggle one of the bytes from a "0" to indicate the device is off,
- to a "1" to indicate the device is on. The status of the device
- (whether it is on or off) is continually toggled after a random
- amount of time has passed. The sub-processes use the initial
- value in BX as an index into the status line to compute which
- byte to update.
-
- Another shared value in the data segment is an abort flag. The
- sub-processes monitor this byte. When its value becomes 1, each
- of the sub-processes will abort itself. The main process sets
- this value to one when a character is typed at the keyboard.
- This is one way for a main process to terminate its sub-
- processes. Note that simply pressing control-c at the console
- will not suffice. This will only terminate the main process,
- leaving all of the sub-processes running in background until
- either the ABORT or STOP command is used on each of them, or the
- system is re-booted.