From: Steve Tuckner Date: 2002-12-04T08:01:35+09:00 Subject: Fox threading issues This is a multi-part message in MIME format. ------=_NextPart_000_034D_01C29AED.8F708D80 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit I have a simple program (down below) that causes different failures on the 1.6.7 MSC build (from RubyCentral) and on Linux with 1.6.7. On Windows the program just locks up. On Linux (as on cygwin) it runs for a while and then seg faults. Any ideas anyone? Steve Tuckner require "thread" require "fox" include Fox class MainWindow < FXMainWindow def initialize(app) # Invoke base class initialize first super(app, "Main Window", nil, nil, DECOR_ALL, 0, 0, 400, 200) menubar = FXMenubar.new(self, LAYOUT_SIDE_TOP|LAYOUT_FILL_X) # File Menu filemenu = FXMenuPane.new(self) FXMenuCommand.new(filemenu, "&Quit", nil, getApp(), FXApp::ID_QUIT, 0) FXMenuTitle.new(menubar, "&File", nil, filemenu) label = FXLabel.new(self, "Count: ") @countLabel = FXLabel.new(self, "0") button = FXButton.new(self, "Reset Count") button.connect(SEL_COMMAND) do $count = 0 end end def onTimeout(sender, sel, ptr) $lock.synchronize { @countLabel.setText($count.to_s) } getApp().addTimeout(100, method(:onTimeout)) end def create super show(PLACEMENT_SCREEN) getApp().addTimeout(100, method(:onTimeout)) end end $count = 0 $lock = Mutex.new w = Thread.new do loop do #File.open("thrd.rb", "r") do |f| #data = f.read #end $lock.synchronize { $count += 1 } sleep 0 end end # Make an application application = FXApp.new("Dialog", "FoxTest") application.init(ARGV) MainWindow.new(application) application.create application.run ------=_NextPart_000_034D_01C29AED.8F708D80 Content-Type: text/html; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable
I = have a simple=20 program (down below) that causes different failures on the 1.6.7 = MSC build=20 (from RubyCentral) and on Linux with 1.6.7. On Windows the program just = locks=20 up. On Linux (as on cygwin) it runs for a while and then seg faults. = Any ideas=20 anyone?
 
Steve = Tuckner
 
require=20 "thread"
require "fox"
 
include=20 Fox
 
class = MainWindow=20 < FXMainWindow
  def initialize(app)
  # Invoke base = class=20 initialize first
  super(app, "Main Window", nil, nil, = DECOR_ALL, 0, 0,=20 400, 200)
 
  menubar =3D FXMenubar.new(self,=20 LAYOUT_SIDE_TOP|LAYOUT_FILL_X)
 
  # File = Menu
 =20 filemenu =3D FXMenuPane.new(self)
  FXMenuCommand.new(filemenu, = "&Quit", nil, getApp(), FXApp::ID_QUIT, 0)
 =20 FXMenuTitle.new(menubar, "&File", nil, = filemenu)
 
  label =3D=20 FXLabel.new(self, "Count: ")
  @countLabel =3D = FXLabel.new(self,=20 "0")
 
  button =3D FXButton.new(self, "Reset = Count")
 =20 button.connect(SEL_COMMAND) do
   $count =3D 0
 =20 end
 end
 
   def onTimeout(sender, sel,=20 ptr)
  $lock.synchronize { 
    =20 @countLabel.setText($count.to_s)
    }
 =20 getApp().addTimeout(100, method(:onTimeout))
   = end
  =20
 def create
  super
  = show(PLACEMENT_SCREEN)
 =20 getApp().addTimeout(100,=20 method(:onTimeout))
 end
end
 
 
$count =3D 0
$lock=20 =3D Mutex.new
 
w =3D Thread.new do
 loop=20 do
 #File.open("thrd.rb", "r") do |f|
   #data =3D = f.read
   #end
 
  $lock.synchronize = { =20
   $count +=3D 1
  }
  sleep=20 0
 end
end
 
# Make an application
application = =3D=20 FXApp.new("Dialog",=20 "FoxTest")
application.init(ARGV)
MainWindow.new(application)
a= pplication.create
application.run
 
 
------=_NextPart_000_034D_01C29AED.8F708D80--