5.2 Issues in multitasking

5.2.3 Nonlocal control transfers

Common Lisp provides the special forms catch and throw to allow a transfer of control in which the destination is determined by the dynamic environment. In addition, the special formunwind-protect ensures that certain cleanup code is always executed, even if there is athrow from within the protected form of theunwind-protect to a tag outside of theunwind-protect.

In the Multitasking Facility, each process maintains its own stack ofcatch tags andunwind-protect forms. When a process uses the special formthrow to perform a nonlocal control transfer, its stack is searched to find the appropriate tag and its unwind-protect cleanup forms are executed; stacks from other processes are not searched.

If your program is running in one process and you need to have another process exit its computation, you can use the functioninterrupt-process to cause the other process to perform a throw, as the following example demonstrates:

(interrupt-process *some-process*
                   #'(lambda () (throw 'tag value)))	

Ifprocess-wait or a related function has suspended*some-process*, this code causes the process to wake up and throw to the appropriate tag. This method is the only way that a process can return from a call to the functionprocess-wait-forever.

When you use the functionkill-process to kill a process, all the unwind-protect cleanup forms that are pending on that process's stack are performed before the process is killed. If a cleanup form contains athrow, ago, or areturn to a location outside of the cleanup form, the unwinding of the stack is aborted.

You can use the optional argument:suppress-unwind-protects tokill-process to kill the process immediately without attempting to execute cleanup forms or to unwind the stack. However, this method of killing a process is dangerous and should only be used as a last resort when a more reasonable method will not work. Files in the process are not closed, locks are not released, and all other details of process cleanup are lost.


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker