The following example allows two (or more) multiplication tables to be printed out simultaneously.
First, the function to print out a multiplication table.
(in-package "USER")
(defun print-table (number total stream)
(do ((i 1 (+ i 1)))
((> i total))
(format stream "~S X ~S = ~S~%" number i (* i number))
(mp:process-allow-scheduling)))
Note the use of
mp:process-allow-scheduling
to allow the process to be interrupted once during each iteration of the do loop.
Now we define the function that calls
print-table
within multiprocessing:
(defun process-print-table (name number total)
(mp:process-run-function name nil
#'print-table number total *standard-output*))
The
nil
argument is used because no keywords are specified.
process-print-table
can now be called from two separate Listener windows to print out different multiplication tables simultaneously, for example:
(process-print-table "t1" 5 50)
(process-print-table "t2" 6 50)