Multithreaded Gtk applications using Ruby bindings freeze

Bug #514899 reported by Aiden Nibali
16
This bug affects 1 person
Affects Status Importance Assigned to Milestone
ruby-gnome2 (Ubuntu)
Fix Released
Medium
Unassigned
Karmic
Fix Released
Undecided
Unassigned

Bug Description

Binary package hint: libgtk2-ruby

In Ubuntu 9.10 with the version of libgtk2-ruby from the repositories (0.19.0), new threads cause the Gtk main loop to freeze. As an example, the following code will never produce any output:

===== Impact =====
I don't know which program available directly within Ubuntu is written in Ruby-GTK+, but those which do and which are using the Ruby Thread class are broken, and of course developing such a program is broken too.

The fix is available in ruby-gnome2 since version 0.19.2 and was introduced through SVN revisions 3692[1] and 3694[2]. Both are within the attachment "ruby-gnome2-gtk-thread-patch.debdiff" in comment #1.

[1] http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2?view=rev&revision=3692
[2] http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2?view=rev&revision=3694

TEST CASE:
 require 'gtk2'

 Thread.new do
   sleep 1 # Look busy
   exit # Finished, exit
 end

 # Main loop
 loop do
   # Process all currently pending events
   Gtk.main_iteration while Gtk.events_pending?
   print '.'
 end

However, when the latest version of the bindings is installed (0.19.3) the program works as expected, filling the screen with dots.

TEST CASE 2:
Here is another example for reproducing this bug:

require "gtk2"
include Gtk, GLib
# Create widgets
window = Window.new
vbox = VBox.new(false, 2)
button = Button.new("Run Thread")
progress = ProgressBar.new
# Pack widgets
window.add(vbox)
vbox.add(button)
vbox.add(progress)
# Set default window size
window.default_width = 120
window.default_height = 50
window.show_all
# Connect signals
button.signal_connect("clicked") do
        Thread.new do
                puts "Thread started!"
  loop do
   progress.pulse
   sleep 1
  end
        end
end
window.signal_connect("destroy") { main_quit }
# Show all and run
main # start the GTK+ main loop

The test program shows a window with a button and a progress bar. Clicking the button will execute a Ruby Thread object, and the GUI visual elements/the GTK+ main loop will remain freezed.

REGRESSION:
The following applications use libgtk2-ruby and threads: fantasdic-1.0beta7 geekast-0.1.3 kazehakase-0.5.8 mhc-0.25.1+20090120 rbbr-0.6.0 xnetcardconfig-0.2.1

The example in the bug description is supposed to print dots, and instead it doesn't.

This problem is also reported at:
http://sourceforge.net/mailarchive/forum.php?thread_name=dc3bf8581001120746kb5da118udd0a74439cc4dcd9%40mail.gmail.com&forum_name=ruby-gnome2-devel-en

Revision history for this message
Mike Massonnet (mmassonnet) wrote :

I attach a patch (debdiff) for the package which fixes the use of Thread objects inside GTK+/GLib main loops. It worked fine for me. The patch includes the two patches from Ruby-GNOME2 0.19.2.

tags: added: patch
Revision history for this message
Mike Massonnet (mmassonnet) wrote :
Revision history for this message
Brian Murray (brian-murray) wrote :

This is fixed in the Lucid release of ruby-gnome2.

Changed in ruby-gnome2 (Ubuntu):
importance: Undecided → Medium
status: New → Fix Released
Revision history for this message
Mike Massonnet (mmassonnet) wrote :

Proposing as an SRU (help me if I'm doing it wrong):

===== When =====
Has an obviously safe patch.

===== Impact =====
I don't know which program available directly within Ubuntu is written in Ruby-GTK+, but those which do and which are using the Ruby Thread class are broken, and of course developing such a program is broken too.

The fix is available in ruby-gnome2 since version 0.19.2 and was introduced through SVN revisions 3692[1] and 3694[2]. Both are within the attachment "ruby-gnome2-gtk-thread-patch.debdiff" in comment #1.

[1] http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2?view=rev&revision=3692
[2] http://ruby-gnome2.svn.sourceforge.net/viewvc/ruby-gnome2?view=rev&revision=3694

===== Reproduce the bug =====
Here is another example for reproducing this bug:

require "gtk2"
include Gtk, GLib
# Create widgets
window = Window.new
vbox = VBox.new(false, 2)
button = Button.new("Run Thread")
progress = ProgressBar.new
# Pack widgets
window.add(vbox)
vbox.add(button)
vbox.add(progress)
# Set default window size
window.default_width = 120
window.default_height = 50
window.show_all
# Connect signals
button.signal_connect("clicked") do
        Thread.new do
                puts "Thread started!"
                progress.pulse
        end
end
window.signal_connect("destroy") { main_quit }
# Show all and run
main # start the GTK+ main loop

The test program shows a window with a button and a progress bar. Clicking the button will execute a Ruby Thread object, and the GUI visual elements/the GTK+ main loop will remain freezed.

The example in the bug description is supposed to print dots, and instead it doesn't.

Revision history for this message
John Dong (jdong) wrote :

Hi Mike,

Thanks for proposing this as a SRU. I just reviewed your patch, and everything seems reasonable to me. The only corrections are minor and procedural:

(1) The information in comment #4 should be placed in the original bug description.
(2) The version number of the updated package should be 0.19.0-2ubuntu4.1 according to our SRU conventions
(3) the upload target suite is "karmic-proposed", not "karmic".

Pending these changes, consider this an ACK from ubuntu-sru.

Revision history for this message
Mike Massonnet (mmassonnet) wrote :

Updated patch with karmic-proposed and version ubuntu4.1. Thanks for your comments :)

Revision history for this message
Benjamin Drung (bdrung) wrote :

I removed ~ppa1 from the version string, changed "Changes" to "LP", and uploaded it.

Revision history for this message
Martin Pitt (pitti) wrote : Please test proposed package

Accepted ruby-gnome2 into karmic-proposed, the package will build now and be available in a few hours. Please test and give feedback here. See https://wiki.ubuntu.com/Testing/EnableProposed for documentation how to enable and use -proposed. Thank you in advance!

Changed in ruby-gnome2 (Ubuntu Karmic):
status: New → Fix Committed
tags: added: verification-needed
Revision history for this message
Martin Pitt (pitti) wrote :

Anyone who can test this?

description: updated
description: updated
description: updated
description: updated
Revision history for this message
Jean-Baptiste Lallement (jibel) wrote :

SRU verification for Karmic:
I have reproduced the problem with ruby-gnome2 0.19.0-2ubuntu4 in karmic and have verified that the version of ruby-gnome2 0.19.0-2ubuntu4.1 in -proposed fixes the issue.

I have run the 2 test cases in the description and the test in the upstream report. I have modified the 2nd test case provided by Mike in order to reproduce the blocking wait.
I have also tested rbbr and fantasdic, which one is much more responsive with the new version of the library, and I haven't noticed any regression.

Marking as verification-done

tags: added: verification-done
removed: verification-needed
Revision history for this message
Launchpad Janitor (janitor) wrote :

This bug was fixed in the package ruby-gnome2 - 0.19.0-2ubuntu4.1

---------------
ruby-gnome2 (0.19.0-2ubuntu4.1) karmic-proposed; urgency=low

  * debian/patches/gtk-threads.patch: apply two patches from ruby-gnome2 0.19.2
    to fix a problem with threads freezing the GTK+ main loop (LP: #514899).
 -- Mike Massonnet <email address hidden> Fri, 19 Feb 2010 02:04:05 +0100

Changed in ruby-gnome2 (Ubuntu Karmic):
status: Fix Committed → Fix Released
Revision history for this message
Ayan George (ayan) wrote : I added your profile to my contact list

Hello!
I am Olesia, I am 27 y.o.
I search for boy-friend.
Ny photos and mew message for you here:

http://sonya201010.com.ua/?message_from=Olesia

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.