All Manuals > LispWorks User Guide and Reference Manual > 15 Multiprocessing > 15.2 The process programming interface


15.2.10 Example

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))

Note the use of 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)

in one Listener and:

(process-print-table "t2" 6 50)

in another Listener.

LispWorks User Guide and Reference Manual - 21 Dec 2011