Next Previous Up Top Contents Index

11.2 The process programming interface

11.2.6 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))
 (mp:process-allow-scheduling)))

Note the use ofmp:process-allow-scheduling to allow the process to be interrupted once during each iteration of the do loop.

Now we define the function that callsprint-table within multiprocessing:

(defun process-print-table (name number total)
  (mp:process-run-function name nil
    #'print-table number total *standard-output*))

Thenil 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 - 14 Oct 1998

Next Previous Up Top Contents Index

Generated with Harlequin WebMaker