5.3 Debugging under multitasking

5.3.3 Multiple processes using the same stream

Unless you take special action, all processes use the standard streams by default. All of the standard streams are synonym streams for*terminal-io*, which has a global default value. This arrangement occasionally has undesirable results. For example, if two processes send output simultaneously to a standard stream, the two outputs can be intermingled on the screen.

A more confusing situation occurs when two processes are simultaneously waiting for input; then any input line that you type is passed to one of the processes at random. This condition arises most often when a process that generally does not require input or output ends up in the Debugger. When you are in this situation, Debugger commands have unpredictable results. For example, typing:b might not produce the same backtrace in successive attempts; sometimes it might just print:B rather than backtracing. You can verify this problem by checking the value of the variable *current-process* repeatedly.

If you find that two processes are using the same stream, you should try to disable one process so that you can interact with the other without interference. For example, assume you had a reading function calledmy-reading-function that took a stream and a process argument. If you wanted the processmy-process to read from the stream*stream*, but another process was also reading from*stream*, you could isolate the interaction tomy-process with the following code:

(with-scheduling-inhibited
  (clear-input *stream*)
  (my-reading-function 'my-process *stream*))

In this case, no other processes can be scheduled whilemy-process reads from the stream.

If you need more than one process to be running at a time, you cannot disable the scheduler. If there are only two competing processes and you know the name of each, you could use this method to isolate the reading tomy-process:

(unwind-protect
     (progn
       (deactivate-process 'other-process)
       (clear-input *stream*)
       (my-reading-function 'my-process *stream*))
  (activate-process 'other-process))

In either case, you should clear the stream before reading from it.


The Advanced User's Guide - 9 SEP 1996

Generated with Harlequin WebMaker