Thanks Tristian and Jan for the answers. I'm not calling
while ( gtk_events_pending ()) gtk_main_iteration (); from event handlers, they are being called from the main thread. I have several threads running in my program. Two are the threads created by PortAudio which read audio data into or out of ring buffers. The output ring buffer is only written to by the main thread, the input ring buffer is only written to by the the PortAudio thread. Audio processing is then done by my main thread. My gtk event handlers typically change the values of variables. The main thread then notices that the values have changed and performs the necessary actions. My program is (I believe) simple enough so that this mechanism for communicating GUI events to the main thread should be sufficient. I hope. Very early on I noticed that if I called gtk_main_iteration() from a secondary thread while the main thread was running gtk_main() that gtk complained. That's when I deleted gtk_main(), and made the secondary thread the primary one. Everything seems to be working since then, but I was concerned about traps for young players. I think I have avoided problems of reentrant code. E.g. I have a "record" button. If the button is pressed again during recording or processing of audio, the main thread will go back and start recording again from scratch. This seems to me, without going into great detail about my program, a reasonable user interface. Although while writing this paragraph I went over and fixed a tiny bug by making sure that the text of my progress bar was reset to "recording" if this happens :-) Cheers, Ross-c On Wed, 2006-04-12 at 15:01 +0100, Andersen, Jan wrote: > Ross Clement wrote: > > Hi. I find myself writing a program that processes the gtk gui events > > itself. E.g. code vaguely similar to the pseudo-code: > > > > while( large_compute_bound_job_not_finished ) > > { > > process_next_block_of_data(); > > gtk_progress_bar_set_fraction( progressBar, fraction ); > > > > while ( gtk_events_pending ()) > > gtk_main_iteration (); > > } > > > > Is this something that it is frequently sensible to do, or have I fallen > > into a big newbie trap? > > > I'm not sure I understand you correctly, but one thing to think about is > reentrance; are the screen update functions reeantrant? I remember from my > Windows days (now happily in the remote past) that anything to do with the > desktop was not reentrant. What that means is that you can not update the > screen from anything other than the main thread; I have got used to simply > avoiding that, so I don't know if X can handle it. > > One trap Windows programmers always used to fall in was to update a progress > indicator whenever a network packet arrived; this went well as long as the > update managed to return before the next packet arrived, but it caused > intermittent errors and crashes when the load got too big. > > /jan > _______________________________________________ > gtk-app-devel-list mailing list > gtk-app-devel-list@gnome.org > http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list _______________________________________________ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org http://mail.gnome.org/mailman/listinfo/gtk-app-devel-list