[Glade-users] uni- versus multi-threaded gtk
- From: pdbuchan at yahoo.com (David Buchan)
- Subject: [Glade-users] uni- versus multi-threaded gtk
- Date: Sat, 25 Jun 2011 11:08:50 -0700 (PDT)
Typo correction: the main calc while loop should've read
while (flag == 1) {
--- On Sat, 6/25/11, David Buchan <pdbuchan at yahoo.com> wrote:
From: David Buchan <pdbuchan at yahoo.com>
Subject: Re: [Glade-users] uni- versus multi-threaded gtk
To: "Russ Mannex" <russ at mannex.com>
Cc: glade-users at lists.ximian.com
Date: Saturday, June 25, 2011, 2:01 PM
Thanks Russ!
I thought this would be a common situation and there should be a simple solution.
And indeed there was!
For anybody else following this discussion, I just inserted a few lines inside my calculation loop like so:
// main calculation loop
while (flag == 0) {
? make some heavy duty calculations;
// Check if the user has clicked any buttons (e.g., the STOP button)
??? while (gtk_events_pending()) {
????? gtk_main_iteration();????? // let the main gtk loop deal with it
??? }
? carry on with more ridiculously heavy duty calculations;
}
The way I set it up, if the user clicks the STOP button, a callback is executed which sets the flag to zero
(flag = 0). The main calculation while-loop then ends
peacefully.
Thanks again Russ. Awesome tip.
Dave
--- On Sat, 6/25/11, Russ Mannex <russ at mannex.com> wrote:
From: Russ Mannex <russ at mannex.com>
Subject: Re: [Glade-users] uni- versus multi-threaded gtk
To: "David Buchan" <pdbuchan at yahoo.com>
Cc: glade-users at lists.ximian.com
Date: Saturday, June 25, 2011, 12:14 AM
Check out the documentation on the event loops. You want to do your calculations inside an event loop. That
way, if there's no event, it keeps going. If there is an event, it can act on it.
--
Mannex
On Fri, 2011-06-24 at 20:18 -0700, David Buchan wrote:
Hi guys,
I have written a c program with gtk builder user interface. The user presses a button which starts
calculations and a graph to begin to be drawn. The calculations are very slow and so I want the user to be
able to click a stop button to end it if they wish.
I've done it with multi-threading, so that the calculations are started in a new thread, leaving the ui still
available for the user to click a button which changes the state of a flag. The calculations are within a
while loop which keeps going or stops depending upon the state of the aforementioned flag.
But it seems crazy to me that I should need to do this simple thing with multi-threading.
I have this feeling there should be a way to do the computation within a while loop or something (without
multi-threading) that is contingent upon receiving or not receiving a signal from a button. Sort of like:
while (! on_button_clicked) {
...compute
stuff...
}
Can anyone give me advice here. Multi-threading seems to be overkill, and in fact, gives the user too much
latitude to go off clicking other stuff I don't want them clicking. The ONLY thing the user need do while the
program is working on the graph, is click a Stop button.
Thanks,
Dave
_______________________________________________
Glade-users maillist - Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
-----Inline Attachment Follows-----
_______________________________________________
Glade-users maillist? -? Glade-users at lists.ximian.com
http://lists.ximian.com/mailman/listinfo/glade-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/glade-users/attachments/20110625/e8da400c/attachment.html
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]