FOX multithreading

I’m about to embark on multithreading a FOX-based GUI (to add to the contents of an FXTreeList in the background) and I remember there being issues with multithreading in Tk … ie, the threads didn’t get a look-in unless you used a Tk method to schedule them for idle processing.

Does FX/Ruby have a similar issue? If so, can someone point me at an example, or tell me the right class/method to look up?

TIA

···

Harry Ohlsen
QIQ Solutions
E-Mail: harryo@qiqsolutions.com
Web: http://www.qiqsolutions.com/
Phone: +61 2 9209 4171

Harry Ohlsen wrote:

I’m about to embark on multithreading a FOX-based GUI (to add to the
contents of an FXTreeList in the background) and I remember there being
issues with multithreading in Tk … ie, the threads didn’t get a
look-in unless you used a Tk method to schedule them for idle processing.

Does FX/Ruby have a similar issue? If so, can someone point me at an
example, or tell me the right class/method to look up?

Support for Ruby threads with FXRuby is enabled by default. That is,
FOX’s event loop will periodically yield control to Ruby’s thread
scheduler to let threads other than the main thread do their thing.

One issue to be aware of is that this wouldn’t work properly on Windows
for Ruby versions 1.6.7 and earlier. The underlying bug was fixed in
Ruby 1.6.8 (as well as the 1.7.x series).

For a really, really trivial example of this, take the ‘groupbox.rb’
example that comes with FXRuby and uncomment this block of code starting
around line 390:

 # Create a thread to update the clock
 @clockThread = Thread.new(@clockLabel) { |clockLabel|
   while true
     clockLabel.text = Time.now.strftime("%I:%M:%S %p")
     sleep(1)
   end
 }

This bit creates a thread that continously updates the “clock” label
that appears in the lower right-hand corner of the main window.

Hope this helps,

Lyle