On Fri, 19 Mar 2004, david moss wrote:
> I have been trying to get concurrent processes running in pop11, but so
> far have only been able to start a new process whilst suspending the
> current running process.
Correct.
Essentially the poplog process mechanism implements a system of
co-routines, where running a process using runproc *transfers* control
to that process, and it stays there until that process invokes suspend
(return temporarily to its caller, by returning from the call of
runproc) or resume (suspend followed by runproc). You need to do
more to simulate parallelism.
> This is what I have tried (in a very simplified
> form to illustrate the problem).
>
> define p();
> while true do
> pr("t");
> endwhile;
> enddefine;
>
> lvars proc = consproc(0, p);
> ;;; This doesn't run concurrently!!!
> runproc(0, proc);
This merely hands *total* control over to a process running p().
> I thought this would be similar to if(fork()){...}else{...} in C, but
> here the code never gets to the pr("m"); statement. Can someone point me
> to the correct help file for concurrent processes as it seems I got the
> wrong one?
What you are looking for is something that allows multiple processes
to be started, with a scheduler that interrupts the running one at
certain times and then runs another (using some sort of priority
mechanism).
One way to do that is to make a list of processes, set up a repeated
*timer-based* interrupt mechanism that will suspend the current process
and run the next one. Then you can immediately run the first process,
leaving it to the interrupt mechanism to do the switching thereafter.
See sys_timer in REF TIMES.
That's called 'pre-emptive' scheduling, I believe.
Another way is to make each process internally decide when to pause
and suspend itself so that another can then run. That may often be
better if an arbitrary timer interrupt could leave something in a
dangerous or meaningless state that cannot be resumed later.
For that strategy your procedure p() would perhaps call suspend
after every N cycles. Then something else would have to re-start
it each time.
The SimAgent toolkit essentially uses a non-preemptive scheduler,
though because it uses rule-based mechanisms at the top level rather
than pop11 procedure calls, it does not use consproc, runproc etc.
(An earlier version did use pop11 processes, and they can still be added
to SimAgent with timer-interrupts for some sub-processes, if needed).
An example of the use of a preemptive scheduler can be found in
TEACH OPSYS, originally written by Chris Thornton for teaching
operating system concepts, before sys_timer exists.
It uses a slightly different mechanism, syssettimer, which still
works, but is obsolete. It is defined in terms of sys_timer in
$popsrc/sys_timer.p
Anyone who does not have TEACH OPSYS can fetch it from here:
http://www.cs.bham.ac.uk/research/poplog/teach/opsys
There is a different approach using processes described in
HELP ACTOR, using LIB ACTOR, a discrete event simulation
package originally due to Jonathan Cunningham. This uses
consproc, etc. with non-preemptive scheduling,
There are some low level concurrent processes in the poplog
system whenever XVed or certain X11 applications are running
which need to be able to detect mouse and keyboard events.
Also some of the file handling stuff described in REF SYSIO
depends on asynchronous concurrent processes, e.g. sys_async_io.
The signal handling also runs asynchronously. See REF ASYNC
(I don't know much about the gory low level details, except that I
know I am using them a lot in the RCLIB package, e.g. that's what
makes it possible for the mouse to move things around on the
screen while a program is running and moving other things round
in the same window. Each TEACH sim_sheepdog.p)
Finally, using sys_fork (see REF SYSUTIL) you can make the current
poplog process fork a copy of itself which can then use sysexecute
to change the copy to be different from the original, just as in
a C program.
After that the different processes run in parallel under the control of
the unix/linux scheduler. If you have N cpus in a symmetric
multi-processor system, then N of them might really run in parallel
(as in some of our Sun servers).
See also HELP RUN_UNIX_PROGRAM It shows how to use pop11 to create
a Unix C shell process, send commands to it, and receive the input.
If the 'wait' argument is false the run_unix_program command
sets up another unix/linux process that runs in parallel with the
first.
Have fun.
Aaron
|