Does calling kernel#select stop all ruby threads while it is waiting
or does the interpreter run the select on a different kernel thread?
By running the select on another kernel thread other ruby threads
could run while this call is blocked.
If select isn't using kernel threads, what the strategy in ruby to
leave a select outstanding while other things get done?
Does calling kernel#select stop all ruby threads while it is waiting
or does the interpreter run the select on a different kernel thread?
By running the select on another kernel thread other ruby threads
could run while this call is blocked.
Ruby multiplexes it behind the scenes, using just one native thread.
If one ruby thread does a select and would block, ruby will switch
to a different ruby thread. If all ruby threads wanted to select
and block, ruby's scheduler would really do a blocking select.
The catch is that some system calls, like write() or send() may block
the whole native process thread, causing all of ruby's green threads
to block. In practice you can usually avoid this on Unix systems
with:
From: "Jon Smirl" <jonsmirl@gmail.com>
> Does calling kernel#select stop all ruby threads while it is waiting
> or does the interpreter run the select on a different kernel thread?
> By running the select on another kernel thread other ruby threads
> could run while this call is blocked.
Ruby multiplexes it behind the scenes, using just one native thread.
If one ruby thread does a select and would block, ruby will switch
to a different ruby thread. If all ruby threads wanted to select
and block, ruby's scheduler would really do a blocking select.
How does this work when the ruby threads are all idle? Something like:
if ruby threads waiting, select with zero timeout; if no ruby threads
waiting select with 100ms timeout? Then it keeps reissuing selects to
simulate my higher level timeout I set on kernel#select?
Any future plans for ruby to use kernel threads instead of green ones?
···
On 12/23/05, Bill Kelly <billk@cts.com> wrote:
The catch is that some system calls, like write() or send() may block
the whole native process thread, causing all of ruby's green threads
to block. In practice you can usually avoid this on Unix systems
with:
> From: "Jon Smirl" <jonsmirl@gmail.com>
> > Does calling kernel#select stop all ruby threads while it is waiting
> > or does the interpreter run the select on a different kernel thread?
> > By running the select on another kernel thread other ruby threads
> > could run while this call is blocked.
>
> Ruby multiplexes it behind the scenes, using just one native thread.
> If one ruby thread does a select and would block, ruby will switch
> to a different ruby thread. If all ruby threads wanted to select
> and block, ruby's scheduler would really do a blocking select.
How does this work when the ruby threads are all idle? Something like:
if ruby threads waiting, select with zero timeout; if no ruby threads
waiting select with 100ms timeout? Then it keeps reissuing selects to
simulate my higher level timeout I set on kernel#select?
If *all* ruby threads go to sleep forever, ruby's scheduler will
abort with a "deadlock" error. Otherwise, I believe it just select's with the shortest timeout appropriate.