[comp.sys.mac.programmer] interrupting uncooperative programs

philip@Pescadero.Stanford.EDU (Philip Machanick) (06/11/90)

For some time, there has been a thread on comp.arch about cooperative
multitasking considered harmful/considered great (more contradiction
than debate: "yes it is", "no it isn't"). One of the points which came
up is the Mac model has no concept of asynchronous interrupts. For
example, if you port a number crunching program to the Mac, you would
have to hack in calls to get/waitnextevent to allow context switching.

One of the comments on this issue was that the Mac OS doesn't support
interrupts, only polling. This is of course untrue; VBL tasks and IO
completion routines come to mind. The best example though is the way
debuggers take control when the interrupt button is pushed (TMON
comes with an Init which allows you to use other keystrokes instead).

This is of course only a half answer to the objection. In unix, I can
interrupt any program (assuming it hasn't deliberately disabled
interruption) by typing CONTROL-z, or kill it by typing CONTROL-c.
After CONTROL-z, I can restart the program in the foreground or
background, and none of this requires knowledge of a low-level
debugger on my part, or any special action by the programmer.

How difficult would it be to make some general program interrupt
feature for the Mac, given that debuggers already do what is essentially
required?  Some features I'd like:

o user-settable keystroke (e.g., COMMAND-SHIFT-.)
o options after interrupt: push to background and switch to another
  application (most obvious implementation: make the apple menu available)
o kill application (ideally with some way of telling it to save files
  and clean up - though this may be impractical if our starting assumption
  is that the program isn't looking at the event queue)

Some of this may be difficult in view of the unpredictable state of the
application heap when an interrupt occurs; the minimum functionality I
would like to see would be a few easy-to-use options when I hit interrupt,
without requiring knowledge of a low-level debugger.

Anyone keen to work on this? I can supply more ideas, but lack the time/
Mac programming experience to get it working.

Philip Machanick
philip@pescadero.stanford.edu