S
spibou
Olivier said:Dear all,
Some background first:
I have a gtk window where my user pushes some
buttons with a definite pleasure. It usually
amounts to asking the program to try all possible
permutations which can take a long time... and
in between my user wants to change some parameters,
or simply wants to stop. Regularly this programm
outputs some messages corresponding to its state.
So how to do this properly? I can add a button
with "Stop" written on it, but what will it do???
This signal is caught, ok, and then?
Should I use a global variable, a USER_INTERRUPTION
that my Stop-button would put to true and check
regularly for its value?
Any comments on how this is usually and properly done
are most welcomed!! Or sample code, or pointers.
I have been wondering about a similar thing myself. The
only answer I could come up with was pretty much what
you're suggesting ie modifying a global variable and have
the part of the programme which performs the calculations
check regularly about the value of the variable. The tricky
part is to arrange things so that the programme checks often
enough as to not appear to be unresponsive but not so often
that it significantly slows down the calculations.
I haven't actually written any code which does this but pretty
much every chess playing programme will have some such
functionality so you could try and read their code. Crafty for
example is open source and it allows the user to enter input
from the keyboard while it does its calculations. It does its job
pretty well so your answer is hidden in its code. But it's a big
programme so it might be tricky to find it.
Hopefully others will have a more straightforward reply.
Spiros Bousbouras