Other Interrupt-Based Optimizations

In general, Mailbox can be tailored to take advantage of most any interrupt-driven resource. For example, personal computers waste most of their processing power waiting for keystrokes. Suppose we wanted to suspend tasks waiting for keyboard I/O, without modifying standard functions, like scanf (), which may access the keyboard. On the IBM PC, the keyboard is typically read through a ROM BIOS software interrupts. Also, the keyboard generates a hardware interrupt each time a key is pressed. By intercepting requests to read the keyboard, and signaling when a key is available (see figure), it is possible to put this idle time to more productive uses – like saving your work!

Figure: MPRES: Intercepting Interrupts (Advanced Optimizations)
\begin{figure}
\begin{verbatim}
IBM PC INTERRUPT IBM PC ROM BIOS
VECTO...
...
optimizations are possible without rewriting the scheduler. }
\par
\end{figure}

A similar trick can be done in UNIX with the signal (3C) and fcntl (2). The calling task must explicitly wait for a mailbox, associated with a particular stream, if an I/O operation on the stream EWOULDBLOCK; in turn, a signal handler for SIGIO would restart the task by sending it a message that the stream was ready.

Likewise optimizations could be made for the other computer resources.

In short, resource management is a difficult issue. Since computer devices differ and most languages several have wired-in I/O calls, portable resource management is nearly impossible, short of writing another operating system. Mailbox provides portable processor (pre-emptive multitasking), memory (dynamic allocation) resource management, and contention management for many standard resources. Beyond this, the programmer is encouraged to tailor Mailbox to her particular resource needs.