[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

Why Thread.pass is so slow?

Hui Gu

8/6/2006 5:03:00 AM

Hi, I'm absolutely new to Ruby, but one thing I found strange is that
thread.pass takes a very long time compare to sched_yield in C. Does
any one know why is that?

--
Posted via http://www.ruby-....

2 Answers

Dido Sevilla

8/6/2006 5:39:00 PM

0

On 8/6/06, Hui Gu <hgu005@ec.auckland.ac.nz> wrote:
> Hi, I'm absolutely new to Ruby, but one thing I found strange is that
> thread.pass takes a very long time compare to sched_yield in C. Does
> any one know why is that?

Remember that at this time Ruby uses green threads, not OS threads.
There's an internal thread scheduler in the Ruby interpreter that
takes care of the whole mechanism of Ruby theading, so everything
happens in userspace, and it would necessarily be slower than the
OS-level POSIX threads you seem to be accustomed to using. I believe
there's some work being done to provide native threads for Ruby, but
it won't be available at least until Ruby 2.0 comes out.

Simon Kröger

8/6/2006 7:04:00 PM

0

Hui Gu wrote:
> Hi, I'm absolutely new to Ruby, but one thing I found strange is that
> thread.pass takes a very long time compare to sched_yield in C. Does
> any one know why is that?

The last time i checked Thread#pass was implemented more like a sleep
for 6ms. I was able to use (from C) a sleep with 1ms in a close loop
without getting into problems (that was short enough for me).

cheers

Simon