On Mon, 8 Sep 2008 23:16:44 +0200 (MEST) "DANIELLLANO@xxxxxxxx" <DANIELLLANO@xxxxxxxx> wrote: > I just saw Havoc's blog entry "SYNCHRONOUS IO NEVER OK": > http://log.ometer.com/2008-09.html#7 > > and I wondered if there is a > http://en.wikipedia.org/wiki/SwingWorker > like interface in glib to run blocking code outside the glib main loop > to prevent locking the gtk+ GUI? > > Do you guys know an easy solution like SwingWorker for glib? You can do non-blocking reads and writes with GIOChannel without having to start any new threads and it is not much more difficult than blocking reads - you set it non-blocking with g_io_channel_set_flags(), plumb it into the main loop with g_io_add_watch() and read whatever happens to be available in your callback function (until you get G_IO_STATUS_AGAIN returned on the iochannel read), and keep on doing that until you reach end of file or you have obtained whatever you were expecting. At that point you can remove the watch. However, if you really need blocking reads (not very likely), you can start a new thread to do the work - see: http://library.gnome.org/devel/glib/stable/glib-Threads.html You can hand any result back to the main GUI thread with g_idle_add() (g_idle_add() is thread safe). As it happens each thread can have their own main loop (that is, their own GMainContext and GMainLoop objects), although it does not sound as if you need to do that. Chris _______________________________________________ gtk-list mailing list gtk-list@xxxxxxxxx http://mail.gnome.org/mailman/listinfo/gtk-list