[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Korundum and threads

Matthieu Riou

12/13/2007 1:27:00 AM

[Note: parts of this message were removed to make it a legal post.]

Hi,

I'm trying to write a small daemon that would display a tray icon in the KDE
task bar. The icon parts works perfectly well but starting the execution of
the KDE application blocks all other threads. For example if I do something
like:

Thread.new { print "."; sleep(0.5) }
app = KDE::Application.new
tray = TrayHandler.new
tray.show
app.exec

Then the thread I started first gets stopped. I'm guessing there's a native
call here that doesn't play well with Ruby green threads but is there a way
to ask the Application to run in the background without disrupting the
execution of other threads?

Thanks!
Matthieu

4 Answers

fedzor

12/13/2007 2:09:00 AM

0


On Dec 12, 2007, at 8:27 PM, Matthieu Riou wrote:

> Thread.new { print "."; sleep(0.5) }
> app = KDE::Application.new
> tray = TrayHandler.new
> tray.show
> app.exec
>
> Then the thread I started first gets stopped.

How certain are you that it's your OS thats stopping the thread, and
not just the thread running out?

Try this for a thread

Thread.new { 1000000.times {|o| print o }

and post back the results.

-Ari

John Carter

12/13/2007 3:58:00 AM

0

On Thu, 13 Dec 2007, Matthieu Riou wrote:
> Then the thread I started first gets stopped.

Personally I wish
Thread.abort_on_exception=true
was the default so things didn't just silently vanish.



John Carter Phone : (64)(3) 358 6639
Tait Electronics Fax : (64)(3) 359 4632
PO Box 1645 Christchurch Email : john.carter@tait.co.nz
New Zealand


Alex Fenton

12/13/2007 7:35:00 AM

0

Matthieu Riou wrote:

> Then the thread I started first gets stopped. I'm guessing there's a native
> call here that doesn't play well with Ruby green threads but is there a way
> to ask the Application to run in the background without disrupting the
> execution of other threads?

I don't use Korundum, but generally GUI toolkits don't work well out of
the box with Ruby's green threads, because when they're in the event
loop, non-GUI threads don't get scheduled.

The usual solution is to use the GUI toolkit's Timer class (eg
Qt::Timer, Wx::Timer) which fires at a short, regular interval. When it
fires, call something like Thread.pass or sleep, which will allow Ruby
to give execution time to other threads.

On Qt:
http://www.lesismore.co.za/Q...

On wxRuby:
http://rubyforge.org/pipermail/wxruby-users/2007-April/0...

hth
alex

Joel VanderWerf

12/13/2007 8:01:00 AM

0

John Carter wrote:
> Personally I wish
> Thread.abort_on_exception=true was the default so things didn't just
> silently vanish.

Then you lose Thread#value:

#Thread.abort_on_exception=true

th = Thread.new do
raise ArgumentError, "I'm sorry, but this is abuse"
end

begin
th.value
rescue => ex
puts ex.message
end

--
vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407