Re: Handling Unix signals in a GTK+ application




Going back to your original point, it is definitely not a
"busy wait".

I just rolled together a quick test...  A GTK main loop running two "sources".

First an "event source" created using g_timeout_add() that prints the current count each second, and halting 
the program (via gtk_main_quit() ) after the 10th count.

Second, an idle event crated though g_idle_add() that simply increments said counter and returns true to 
repeat (similar to what you'd have watching for a flag indicating a Unix signal had occured).

The program ran for 10 seconds, giving counts of:
** Message: Ticker Tocker...  9 -> 160565
** Message: Ticker Tocker...  8 -> 343367
** Message: Ticker Tocker...  7 -> 545729
** Message: Ticker Tocker...  6 -> 703564
** Message: Ticker Tocker...  5 -> 856554
** Message: Ticker Tocker...  4 -> 1018223
** Message: Ticker Tocker...  3 -> 1219280
** Message: Ticker Tocker...  2 -> 1390704
** Message: Ticker Tocker...  1 -> 1548533

My CPU usage graph applet showed a 100% CPU burn during that time, however oddly the output of the system 
"time" command showed:
   real:10.587s user:2.172s sys:7.224s
If that means anything useful.  I'm guessing from that that the program is spending a good deal of its time 
in select(), with a zero timeout (causing it to return immediately each time).

That's well over 1548533 executions (I forgot to print the counter after the 10th second) of the idle 
callback, or 172059 calls to the idler function per second.

Personally, I'd call that a busy wait.


The source code to my little test program (incase I did something very very wrong), goes something like this:

#include <gtk/gtk.h>
gint count_down = 10, iterations = 0;
gboolean tickertocker() {
  if ( --count_down <= 0 ) {
    g_message("Countdown go kabloowie!");
    gtk_main_quit();
    return;
  }
  g_message("Ticker Tocker...  %i -> %i", count_down, iterations);
  return TRUE;
}
gboolean idle_function() {
  ++iterations;
  return TRUE;
}
int main(int argc, char* argv[]) {
  // Initialize the widget set
  gtk_set_locale();
  gtk_init(&argc, &argv);
  // Initialize application components
  g_timeout_add(1000, (GSourceFunc) tickertocker, NULL);
  g_idle_add( (GSourceFunc) idle_function, NULL); 
  // Enter the main event loop
  gtk_main();
  // Shutdown application components
  return 0;
}


Fredderic

_______________________________________________
Join Excite! - http://www.excite.com
The most personalized portal on the Web!





[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]