GTK usage within threads

I have spent lots of time looking at various informal and unofficial
documents and messages pertaining to using GDK and GTK in threads. I have
tried to follow the advise received, but I am not sure I have it right.

My threaded applications work OK and are reliable, but I sometimes
experience a performance problem: slow window updates: things hang dead for
a few seconds and then explode with activity. Sometimes I can trigger this
by generating unrelated mouse events or clicking scroll bars, etc. The
symptoms seem to be saying that the main loop is not running as frequently
as it needs and window updates are pending in buffers and not getting

Here is what I am doing, in summary. I hope someone with more expertise can
take a few minutes to tell me if I am doing someting wrong.

main() program

   gtk_init(&argc, &argv);
   build main window, menus, toolbar, text_view window, etc.
   return 0;

main-functions() using GTK: 

   nothing special is done, with the following exception:
   if a main function must block itself due to a conflict 
   with a thread, the following is done to keep the main loop 
   running (and avoid locking-up menus and window updates):

   while (block-condition)
      while (gtk_events_pending()) gtk_main_iteration();
      usleep(1000)         // sleep 1 millisec.
   (I think the problem is here: if I eliminate the usleep()
    and make a hard loop instead, window updates progress 
    at high speed) (not a good solution for obvious reasons)

thread-functions() using GTK:

   gtk calls for dialogs or to update main window
   return 0;

View this message in context:
Sent from the Gtk+ - Dev - General forum at

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