473,786 Members | 2,398 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

How to catch a user interruption?

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_INTERRUPTI ON
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.
Many thanks,
Amities,
Olivier
Aug 23 '06 #1
8 1995
Olivier wrote:
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_INTERRUPTI ON
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

Aug 23 '06 #2
sp****@gmail.co m a écrit :
>[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Aug 23 '06 #3
Olivier wrote:
sp****@gmail.co m a écrit :
>[...] it allows the user to enter input
from the keyboard while it does its calculations.

Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.
--
Flash Gordon
Aug 23 '06 #4
Flash Gordon a écrit :
[...]
Since this is really about how it is best to do things in GTK
[...]

Well, I wondered ... The signal handling is gtk stuff ok.
But the way to do that inside is way out of gtk to me.
Seems more like my dear and lost catch/throw mecanism
or exception stuff. I set the background with gtk to be
clear but that could have been anything, even a shell
thing. I agree that it has to do with inputs and outputs
of a program -- but many programs do have both, even
in C, no ?
A.O.
Aug 23 '06 #5
Olivier wrote:
Flash Gordon a écrit :
[...]
>Since this is really about how it is best to do things in GTK
[...]

Well, I wondered ... The signal handling is gtk stuff ok.
But the way to do that inside is way out of gtk to me.
Seems more like my dear and lost catch/throw mecanism
or exception stuff. I set the background with gtk to be
clear but that could have been anything, even a shell
thing. I agree that it has to do with inputs and outputs
of a program -- but many programs do have both, even
in C, no ?
C had no exception handling. The only mechanisms it has for your program
to detect some asynchronous external event are either if the event
causes a signal which you catch with a signal handler, you could then
set a flag (of type volatile sig_atomic_t) which you could regularly
test in you long running calculation, or you regularly polling to see if
the external condition is true. Neither method is very good for handling
this king of thing. There may, on the other hand, be a good way with
GTK, for example using two threads (which C knows nothing about) one for
the user interaction and one for the long running process. The GTK
people will know whether this or some other solution works best with GTK
(I know that on one Delphi application separate threads for user
interface and high speed serial comms worked well) but we won't here.
I'm only suggesting where you are likely to get the best advice for what
is a very common problem for people writing GUI based applications.

By the way, if you are executing code asynchronously (i.e. handling GUI
events) using any other mechanism that standard C signals then the C
language does not tell you how to avoid synchronisation problems, e.g.
your main code being half way through reading a variable when the
asynchronous code writes to it thus causing you to read half of one
value and half of another, even volatile sig_atomic_t is not guaranteed
for that, only for C signals.
--
Flash Gordon.
Aug 23 '06 #6
Flash Gordon a écrit :
[...]
C had no exception handling. The only mechanisms it has for your program
to detect some asynchronous external event are either if the event
causes a signal which you catch with a signal handler, you could then
set a flag (of type volatile sig_atomic_t) which you could regularly
test in you long running calculation, or you regularly polling to see if
the external condition is true. Neither method is very good for handling
this king of thing. There may, on the other hand, be a good way with
GTK, for example using two threads (which C knows nothing about) one for
the user interaction and one for the long running process. The GTK
people will know whether this or some other solution works best with GTK
(I know that on one Delphi application separate threads for user
interface and high speed serial comms worked well) but we won't here.
I'm only suggesting where you are likely to get the best advice for what
is a very common problem for people writing GUI based applications.
That was first class information!! Thanks!!
A.O.
Aug 23 '06 #7
Flash Gordon wrote:
Olivier wrote:
sp****@gmail.co m a écrit :
[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.

Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.
This thread and any other is "really" about what the posters
make of it. I understood the GTK reference to be just background
material and considered the central point of the thread to be the
following question:

Assume you have a programme which performs many
calculations. Upon receipt of a signal you want the programme
to receive some input from the user and then resume with
the calculations or perhaps start new calculations based on
the input. How can such a thing be implemented in standard
C ?

Even if the original poster considered a GTK solution to
be the central point of the thread that doesn't mean that
the discussion has to terminate right there for not being
topical. As long as the original , possibly not topical question,
inspires a topical one then the discussion can continue on
the topical question. My previous post in the thread did not
mention GTK at all , it concentrated on standard C so it was
perfectly appropriate for here.

Spiros Bousbouras

Aug 24 '06 #8
sp****@gmail.co m wrote:
Flash Gordon wrote:
>Olivier wrote:
>>sp****@gmail.co m a écrit :

[...] it allows the user to enter input
from the keyboard while it does its calculations.
Ok, that's a good additionnal idea.
I'll settle for a global variable.
A.O.
Since this is really about how it is best to do things in GTK and
nothing to do with C itself you would both be best discussing this on
one of the GTK mailing lists. There you will have access to people who
are expert at programming with GTK and maybe even input from the
developers. So you are far more likely to get good advice from there
than from here where we discus C rather than all the myriads of third
party libraries you can call from C.

You may find it useful to read http://clc-wiki.net/wiki/intro_to_clc to
find out some of the regulars ideas about the purpose of the group.

This thread and any other is "really" about what the posters
make of it. I understood the GTK reference to be just background
material and considered the central point of the thread to be the
following question:

Assume you have a programme which performs many
calculations. Upon receipt of a signal you want the programme
to receive some input from the user and then resume with
the calculations or perhaps start new calculations based on
the input. How can such a thing be implemented in standard
C ?
It can't. At least, not without you scattering checks throughout the C
code and there are often *far* better solutions. It also can't be done
unless it is a signal in C terms, and I would be somewhat surprised if
clicking a button in the GUI provided a C type signal.
Even if the original poster considered a GTK solution to
be the central point of the thread that doesn't mean that
the discussion has to terminate right there for not being
topical. As long as the original , possibly not topical question,
inspires a topical one then the discussion can continue on
the topical question. My previous post in the thread did not
mention GTK at all , it concentrated on standard C so it was
perfectly appropriate for here.
I can't remember your post, but I believe you when you say it was
topical. I've also not said that the OP should not have asked the
question. What I've said is that the OP is likely to get better advice
on a GTK mailing list. I've also explained why I believe better advice
will be obtained their. Do you have some objection to me suggesting
where better advice is likely to be obtained? All I am trying to do is
get the OP the best possible help in solving the problem and surely
there is nothing wrong with that.
--
Flash Gordon.
Aug 25 '06 #9

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
6894
by: kaeli | last post by:
Hey all, I'd like to start using the try/catch construct in some scripts. Older browsers don't support this. What's the best way to test for support for this construct so it doesn't kill non-supporting browsers? TIA -- --
8
2737
by: Z D | last post by:
Hi, I was wondering what's the point of "finally" is in a try..catch..finally block? Isn't it the same to put the code that would be in the "finally" section right after the try/catch block? (ie, forget the finally block and just end the try/catch and put the code after the try/catch block). Or does the "finally" construct add some additional functionality?
23
3083
by: VB Programmer | last post by:
Variable scope doesn't make sense to me when it comes to Try Catch Finally. Example: In order to close/dispose a db connection you have to dim the connection outside of the Try Catch Finally block. But, I prefer to dim them "on the fly" only if needed (save as much resources as possible). A little further... I may wish to create a sqlcommand and datareader object ONLY if certain conditions are met. But, if I want to clean these up in the...
6
5052
by: Martin Ortiz | last post by:
Which is best approach? Should Try + Catch be used to only deal with "catastrophic" events (like divide by zero, non-existant file, etc...etc...) Or should Try + Catch be used IN PLACE of regular defensive programming? (ie if file exists do this, if not do something else) Or should Try + Catch be used TO SUPPLAMENT regular defensive programming?
1
974
by: protista | last post by:
I'm trying to Open a form Without Interruption like msn messenger does for an email alert. I'm doing the same thing, but when my form opens up it interrupts my typing... any help?
2
1919
by: CodeSlayer | last post by:
Hi all, This one really has me and the other .Net developers at my work stumped. I have an application that is doing the following: 1 - attempt to validate that user can create a windows task via COM interops 2 - an exception is thrown because user doesn't exist 3 - Exception is caught by calling code shown below:
5
2062
by: Bo Peng | last post by:
Dear list, I have not done a thorough test, but it occurs to me that 1. python code can be interrupted by Ctrl-C. 2. A C module, if I add a main() function and run independently, can be interrupted by Ctrl-C. 3. If I load the C module in python and run, the program will not respond to Ctrl-C interruption. I have to kill python explicitly.
0
1005
by: Nick | last post by:
Hi eveybody, I need some help regarding the mecanism to put in place to be able to dynamically update a remote object when the assembly where it is defined is modified, and this whitout having service interruption. Basically what I'm missing is how do we re-expose a remote object when assembly has changed, and this without any interruption to the callers. I have an application that exposes a remoting object (Well known service -
0
9647
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9496
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10363
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9961
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8989
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
5397
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5534
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4066
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3669
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.