1.9 Threads in a GUI not behaving as expected (Windows)

I have an app with an FXRuby UI that does some fairly heavy data
processing. I’ve implemented an extension to put the processing into
C, so all is right the world there.

The issue is that I’m attempting to kick off the processing in a
separate thread to keep the UI responsive to the user, and it isn’t
working. I was under the impression that 1.9 threads were no longer
“green threads” and shouldn’t behave in this manner since they’re
actual threads now.

I would be perfectly happy using fork for this, except fork isn’t
available on windows and the win32-process gem doesn’t look to be a
solution for me (I’ve already investigated it).

My dev box is a Win7 box, but the clients machine will be a WinXP
machine.

I’ve included an excerpt where I’m creating the thread in the hopes
that someone can help identify why the UI thread appears to be getting
starved for time. There’s not much there, so if you need something
more, please let me know.

Thread.new {
# call extension function
}

Sorry I cannot help you with threads but how about the use of a timer?

here is an extract of code I’ve used to have a timer count down and have
an event fire ever X milliseconds and so allows user GUI interaction to
continue without delays.

NOTE the @timer object allows for the “destruction” or cancellation of
the timer and the creation of it again depending on user events /
actions within the program.

when 3 #Esc Pressed OR clicked on
begin
if @timer == true
@mydb.copy_record(‘patrols’,@PSlist3.getItemText(@PSlist3.currentItem).to_s,‘status’,‘Countdown
STOPPED - CALL ASAP for COMFIRMATION!!’)
$fxapp.removeTimeout(@timeout)
@timer = false
else
Showmsg ‘Msg would be sent to another user and resent until
keys are repressed again!’, ‘ALERT ALERT ALERT…’
@mydb.copy_record(‘some
text’,@PSlist3.getItemText(@PSlist3.currentItem).to_s,‘status’,‘OOPS
PANIC ! - Countdown started!!’)
@timer = true
@timeout = $fxapp.addTimeout(2000*12, :repeat => true) do
|sender, sel, data|
@PSlist2.appendItem("#{Time.now}")
end
end

The magic is this code below…

@timeout = $fxapp.addTimeout(2000*12, :repeat => true) {|sender, sel,
data| @PSlist2.appendItem("#{Time.now}") }

so try this…

def init
@timeout = $fxapp.addTimeout(2000*12, :repeat => true) {|sender, sel,
data| @label1.text = Time.now.strftime("%d/%m/%Y %H:%M:%S")}
end

HTH

Dave.

Your c block needs to be within rb_thread_blocking_region to not block
the (UI responding) ruby threads, I’m thinking.

ref:
http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Thread#Thread

On Mar 23, 9:37am, Roger P. [email protected] wrote:

Your c block needs to be within rb_thread_blocking_region to not block
the (UI responding) ruby threads, I’m thinking.

ref:http://en.wikibooks.org/wiki/Ruby_Programming/Reference/Objects/Threa


Posted viahttp://www.ruby-forum.com/.

Thanks Roger, that’s what I ended up doing, and it’s working
beautifully :slight_smile: