Why Thread.pass is so slow?

H

Hui Gu

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?
 
D

Dido Sevilla

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.
 
S

Simon Kröger

Hui said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,209
Messages
2,571,088
Members
47,686
Latest member
scamivo

Latest Threads

Top