Re: how to program an interrupt button?

Steve Lamont (spl@szechuan.ucsd.edu)
Tue, 11 Mar 97 06:45:04 PST

To subscribers of the xforms list from spl@szechuan.ucsd.edu (Steve Lamont) :

> I would like to know how to best program an interrupt button using Xforms.
>
> Problem to be solved:
> A potentially long computation is performed by an Xforms program, and I want
> the user to be able to interrupt it by pressing on an interrupt button.
>
> [XForms fl_check_forms() and XCheckWindowEvent() solutions elided]
>
> So I should be happy, but am not because this is not XForms programming,
> but really X programming, with calls to XCheckWindowEvent and XPutBackEvent.
>
> Is there any pure XForms-way of obtaining the same result?

Try using an idle callback. This will involve some redesign of your
algorithm to save state at the end of an iteration or a group of
iterations but it will be pure XForms.

Otherwise, a couple of thoughts:

Is your event checking buried down deep in the inner loop of your
calculation? If so, you may wish to bring it up a couple of loops so
that you're not checking for interrupts after every iteration.

If your calculation only consists of one loop then you might consider
a partial unrolling -- do some number of iterations and then test for
your interruption event. You can do this either with a modulo
operator -- something like

if ( ( iterations++ % CHECK_QUANTUM ) == 0 ) {

fl_check_forms();
if ( interrupt )
break;

}

or by actually creating an outer loop in what I hope it the obvious
manner.

You'll have to play with the number of iterations per test in order to
preserve interactivity and still maintain computational efficiency.

spl
_________________________________________________
To unsubscribe, send the message "unsubscribe" to
xforms-request@bob.usuf2.usuhs.mil or see
http://bob.usuf2.usuhs.mil/mailserv/xforms.html
Xforms Home Page: http://bragg.phys.uwm.edu/xforms
List Archive: http://bob.usuf2.usuhs.mil/mailserv/list-archives/xforms-archive/