Ruby-Gnome2 and thread-safety

I’m writing PeerTalk, a TCP LAN chat program. The connections are
handled in separate threads, and they can call the GUI thread at any
time. I’m still trying to find the best way to do this safely.

First, is it safe to call Gtk methods from another thread? Is it enough
for me to just synchronize all my GUI class’s methods with a mutex?

As I understand it, when you change a widget, it schedules an idle
function to redraw itself, which will be called right before Gtk.main
sleeps, at a time when I can’t hold the mutex. I’m worried that if I
change a widget while it’s drawing itself, bad things will happen.

Also, I found that if you change widgets from another thread, they don’t
redraw until an X event comes, which I assume is because the idle redraw
functions aren’t called until the Gtk thread is about to sleep again.

I found that you can force a redraw by calling gtkThread.wakeup.
Apparently this causes Gtk’s rb_thread_select to return, and Gtk runs
the idle functions before sleeping again. Can this be relied upon?
Does anyone know if a similar technique works in FXRuby? On Windows?

Does anyone else have experience making safe multi-threading GUIs
without relying on timeouts?

Thanks for the help,

···


Tom Felker

User friendliness should be hacked onto a pure and simple system,
because
it’s impossible to hack purity and simplicity onto a user-friendly
system.