Article View: comp.lang.prolog
Article #4268Re: Interrupt Handler for Quintus Prolog
From: Don Ferguson
Date: Thu, 08 Mar 1990 21:58
Date: Thu, 08 Mar 1990 21:58
49 lines
2079 bytes
2079 bytes
In article <2030@laura.UUCP> waldmann@exunido.UUCP (Uwe Waldmann) writes:
>I am trying to write an interrupt handler for Quintus Prolog (Rel. 2.4.2 on
>a Sun-3 and/or a Sun-4). I wanted to take the demo example from the
>"Quintus Prolog System-dependent Features Manual" (p. 15) as a starting
>point, but unfortunately even this (unmodified) example does not work
>properly:
The problem you report refects a SunOS bug. Apparently getc() is no longer
re-entrant. If getc() is interrupted and the interrupt handler calls getc(),
then, on return, the original getc() will yield bad values - it's internal
buffer has become corrupted. I proved this to myself by modifying the example
to contain only C code. The code ran correctly under SunOS 2.3, but not under
SunOS 3.2 or 4.0.3.
Avoid the problem by calling read() from the interrupt handler instead of
getchar. (NOTE: getchar is just a macro that calls getc(stdin)).
#include <signal.h>
#include <stdio.h>
#include "/goedel/quintus/install/q2.4.2/library/qpaction.h"
int my_handler()
{
char c, c1;
for (;;) {
printf("\nWell? ");
fflush(stdin);
read(0, &c, 1);
c1 = c;
while (c1 != '\n') {
read(0, &c1, 1);
}
fflush(stdin);
switch (c) {
case 'a': QP_action(QP_ABORT); /* abort */
case 'e': QP_action(QP_EXIT); /* exit */
case 'c': return; /* continue */
default: printf("a, c or e, please");
}
}
}
Thanks for pointing out this discrepancy in our manual. We will update
our documenatation accordingly.
-Don Ferguson
Manager, Technical Services
Technical Details
Message-ID:
<1326@quintus.UUCP>Path:
arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!arisia!quintus!donReferences:
<2030@laura.UUCP>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!utzoo!utgpu!jarvis.csri.toronto.edu!cs.utexas.edu!uwm.edu!bionet!arisia!quintus!don From: don@quintus.UUCP (Don Ferguson) Newsgroups: comp.lang.prolog Subject: Re: Interrupt Handler for Quintus Prolog Message-ID: <1326@quintus.UUCP> Date: 8 Mar 90 21:58:14 GMT References: <2030@laura.UUCP> Reply-To: don@quintus.UUCP (Don Ferguson) Organization: Quintus Computer Systems, Inc. Lines: 49