[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: OOC exception handler
>
> Josef Templ actually defines an exception handling mechanism in his OFront
> product. Maybe we could steal some of his ideas? He basically installs
> an exception handler in his SYSTEM module which get called by a HALT with
> negative numbers. This seems a lot simpler than the elaborate Modula-3
> mechanism. Templ also defines lock variables to protect regions that are
> not reentrant (e.g., X11 library contains non-reentrant procedures).
>
> I agree that the Modula-2 stuff is somewhat of an overkill. I don't
> understand the part about lock variable, though. What are these
> variables guarding, how are locks set and freed? And why should I
> worry about reentrant code?
These variables basically prevent stuff like keyboard interrupts during
execution of code which is non-reentrant. From Templ's report, some of the
X11 routines will crash nicely when interrupted in this fashion. I believe
the way these locks are used is that a variable SYSTEM.lock is incremented
when entering critical code and decremented when exiting. Then, if a
keyboard interrupt occurs and SYSTEM.lock is greater than zero, a boolean
SYSTEM.interrupted flag is set but no action is taken. Then when the
critical region is exited, the SYSTEM.lock is decremented and the flag
can be checked if an interrupt was pending.
Practically, any routines which are non-reentrant (such as most garbage
collectors) have to be locked/unlocked. For example, the following
(from Templ) shows a stub which implements the above:
PROCEDURE Lock();
BEGIN
INC(SYSTEM.lock)
END Lock;
PROCEDURE Unlock();
BEGIN
DEC(SYSTEM.lock);
IF SYSTEM.interrupted & (SYSTEM.lock=0) THEN HALT(-9) END
END Unlock;
PROCEDURE CopyBlock* (xs, sy, w, h, dx, dy, mode: INTEGER);
BEGIN
Lock();
(* call of non-reentrant X-library routines *)
Unlock()
END CopyBlock;
> Each back-end would be free to implement the exception handler hook as they
> require.
>
> Simple and elegant. I vote for stealing :-).
>
> -- mva
Michael G.