Mail Archives: djgpp/1999/12/19/09:49:42
On Sun, 19 Dec 1999, Gerald Hilderink wrote:
> Currently the context switch is delayed until the interrupt returns. The
> problem with delaying interrupts is that somewhere a bit must be checked (by
> polling) in the code. To ensure immediate pre-emptive behaviour this must be
> checked frequently. I have learned that polling seems to be easy and
> flexible, but it is a source for complexity and error-prone.
The DJGPP signal-generation solves this dilemma by triggering an
exception. To that end, the ISR (e.g., the keyboard handler that sees a
Ctrl-C keypress) invalidates the DS selector by setting its limit to the
first 4KB. It also sets a special fake-exception flag, and then the ISR
returns.
Since the DS selector is invalid, the first time the foreground program
tries to access any of its data or stack, a GPF is triggered. The DJGPP
exception handler looks at the fake-exception flag, realizes that this
is a pending signal, and calls "raise (sig)".
That's it! Simple and safe. The SIGINT, SIGALRM and SIGPROF signals
which originate from hardware interrupts are all implemented in this
way, so all the basic machinery is already in place in every DJGPP
program. This is what I suggested for your case as well.
- Raw text -