[DRE-maint] Bug#502262: libgtk2-ruby1.8: Gtk UI rendering hangs when another thread is working
Johan Walles
johan.walles at gmail.com
Wed Oct 15 05:24:49 UTC 2008
Package: libgtk2-ruby1.8
Version: 0.17.0~rc1-6
Severity: normal
I have a GTK program with a UI that is repeatedly updated from another thread using the technique
described here:
http://ruby-gnome2.sourceforge.jp/hiki.cgi?tips_threads
If the updating thread doesn't sleep for *more* than 0.001s every iteration, the UI never gets
updated.
I tried adding Thread.pass to the working thread, but it didn't help.
I expect the UI to be rendered even when another thread is working.
Expected behavior of the sample code below is to display a window with a button saying "Flash
Gordon". Current behavior is to display an empty gray window.
I'm on ruby1.8 1.8.7.72-1.
Regards //Johan
=== Begin sample code
#!/usr/bin/ruby
=begin
This program has a GTK UI that is updated by a separate thread. The
program doesn't work (the UI isn't even rendered) unless the updating
thread sleeps for *over* 1ms sometimes.
Search for FIXME to see what helps and what doesn't.
The failing trials were run on Debian i686 with Ruby 1.8.7.72-1 and
libgtk2-ruby1.8 0.17.0~rc1-6.
johan.walles at gmail.com
=end
require 'gtk2'
require 'monitor'
# From http://ruby-gnome2.sourceforge.jp/hiki.cgi?tips_threads
module Gtk
GTK_PENDING_BLOCKS = []
GTK_PENDING_BLOCKS_LOCK = Monitor.new
def Gtk.queue &block
if Thread.current == Thread.main
block.call
else
GTK_PENDING_BLOCKS_LOCK.synchronize do
GTK_PENDING_BLOCKS << block
end
end
end
def Gtk.main_with_queue(timeout_ms = 100)
Gtk.timeout_add timeout_ms do
GTK_PENDING_BLOCKS_LOCK.synchronize do
for block in GTK_PENDING_BLOCKS
block.call
end
GTK_PENDING_BLOCKS.clear
end
true
end
Gtk.main
end
end
# Create UI
button = Gtk::Button.new("Hello World")
window = Gtk::Window.new
window.signal_connect("destroy") {
Gtk.main_quit
}
# Lay out UI
window.border_width = 10
window.add(button)
window.show_all
Thread.new {
while true
Gtk.queue do
button.label = "Flash Gordon"
end
# FIXME: Sleeping 0.001s does not help:
# sleep 0.001
# FIXME: Sleeping 0.0011s *does* help:
# sleep 0.0011
# FIXME: Thread.pass does not help:
# Thread.pass
end
}
Gtk.main_with_queue
=== End sample code
-- System Information:
Debian Release: lenny/sid
APT prefers testing
APT policy: (990, 'testing')
Architecture: i386 (i686)
Kernel: Linux 2.6.26-1-686 (SMP w/2 CPU cores)
Locale: LANG=sv_SE.UTF-8, LC_CTYPE=sv_SE.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/bash
Versions of packages libgtk2-ruby1.8 depends on:
ii libatk1-ruby1.8 0.17.0~rc1-6 ATK bindings for the Ruby language
ii libatk1.0-0 1.22.0-1 The ATK accessibility toolkit
ii libc6 2.7-14 GNU C Library: Shared libraries
ii libcairo2 1.6.4-6 The Cairo 2D vector graphics libra
ii libgdk-pixbuf2-ruby1.8 0.17.0~rc1-6 Gdk-Pixbuf 2 bindings for the Ruby
ii libglib2.0-0 2.16.6-1 The GLib library of C routines
ii libgtk2.0-0 2.12.11-3 The GTK+ graphical user interface
ii libpango1-ruby1.8 0.17.0~rc1-6 Pango bindings for the Ruby langua
ii libpango1.0-0 1.20.5-2 Layout and rendering of internatio
ii libruby1.8 1.8.7.72-1 Libraries necessary to run Ruby 1.
libgtk2-ruby1.8 recommends no packages.
libgtk2-ruby1.8 suggests no packages.
-- no debconf information
More information about the Pkg-ruby-extras-maintainers
mailing list