Why Ruby 1.9 GUI hangs if i do any intensive computation in separate Ruby thread?

Ruby 1.9 suppose to have native threads, and GIL is supposed to lift
if some threads enters native code (like GUI toolkit main loop or C
implementation of some Ruby lib). But if i start following simple code
sample that displays GUI in main thread and do some basic math in
separate thread - the GUI will hang out badly and dragging window will
redraw ~ every 10 seconds or so :(. I have checked with different GUI
toolkit, Qt (qtbindings gem) - it behaves exactly same. Tested with
Ruby 1.9.3-p0 on Windows 7 and OSX 10.7

require ‘tk’
require ‘thread’
require ‘rexml/document’
Thread.new { loop { a = 1 } }
TkRoot.new.mainloop()

Same code in Python works fine without any GUI hangs:

from Tkinter import *
from threading import *
class WorkThread( Thread ) :
def run( self ) :
while True :
a = 1
WorkThread().start()
Tk().mainloop()

What i’m doing wrong?

Please send this to [email protected]

I dont know how to help you but if you are having gui troble switch API
I have been using this one called QT4 hears a tutorial

http://techbase.kde.org/Development/Tutorials/Qt4_Ruby_Tutorial/Chapter_01

It is simple and comes with a gui for desining guis so cuts out alot of
errors also supports c and its veriations.

All i can do is to quote myself:

I have checked with different GUI toolkit, Qt (qtbindings gem) - it behaves
exactly same.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs