[wxruby-users] Second thread working at slow speed

Alex Fenton
2010-07-08T08:16:35Z

On 07/07/2010 23:42, Chase Wilson wrote:
> I have program that does a bunch of file processing and the GUI froze up
> every time I ran it. I decided to do the trick of running my main code
> in a second thread and using the timer to update the gui every 100 ms.
>

Is there any way you can break up the file processing into small
discrete tasks? If so, you could could have a queue of jobs and consume
them one at a time in an evt_idle loop. This is a more efficient (and
simpler) way of keeping the GUI responsive whilst handling long-running
tasks.

Ruby 1.8 green threads + Wx::Timer has some overhead (thread context
switching) and isn''t that efficient - it forces switching to the GUI
thread when updates aren''t needed.
> However, the problem is that the second thread that I run is working but
> very very slowly. Much slower than how it normally works.
>
> I have the timer:
>        timer = Timer.new(self,ID_ANY)
>        evt_timer(timer.id) {Thread.pass}
>        timer.start(1000)
>

This is switching context every 1000ms - i.e. every second. Did you mean

timer.start(10)

or  (simpler, if you don''t need later control)

Timer.every(10) { Thread.pass }

alex