Why Thread.pass is so slow?

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?

On 8/6/06, Hui Gu [email protected] 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.

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