Ruby threads? the point?

Matt L. wrote:

blinking lights.

Yay! Thanks for the news.
I don’t get to enough conferences…
:_)

On 7/29/06, Eric A. [email protected] wrote:

So how would you implement a simple keyboard-controller
for threads on Windows?

Maybe you can use kbhit() and getch() from msvcrt.dll

kbhit returns whether there are any keystrokes in the buffer
getc returns them.

So, what I do is (or something similar, I don’t have the exact code
here):

kbhit = Win32API.new(‘msvcrt’,‘kbhit’,…)
getch = …

def wait_for_keypress
while true
if kbhit.Call
ch = getch.Call while kbhit.Call # to flush the buffer
return
end
sleep 0.1 # this should allow other threads to run
end
end

J.

Jan S. wrote:

kbhit returns whether there are any keystrokes in the buffer
getc returns them.

Nice! Didn’t know about that kbhit.
That has promise. I wonder if there is a
multi-platform version of that API?

With that capability, I can dispense with
threads altogether, sleep for 1 second
intervals, and look for keyboard input
every time I wake up.

A brain-dead implementation is good enough
for this particular beast…
:_)

On 7/28/06, Charles O Nutter [email protected] wrote:

I hate to make a plug here, but threads under JRuby are native and a
single
one blocking on IO will not prevent others from running. It’s still quite
a
bit slower than C Ruby, but for many applications it’s definitely fast
enough.

I assume I’m misreading you but it sounds like you’re saying that
Ruby’s
green threads block whole processes on I/O. This is not true. I’ve hit
the
Windows-specific problem that is the subject of this thread several
times
and I think it’s either a Ruby-build issue or a Windows-specific
implementation bug. It shouldn’t take 18+ months to find and fix it.

Francis C. wrote:

you can just make it raw with termio calls.

Sounds promising. Do you have a bit of code
to go with the suggestion, perchance?
(I’m having a bit of trouble filling in the blanks.)

On 7/29/06, Eric A. [email protected] wrote:

Nice! Didn’t know about that kbhit.
That has promise. I wonder if there is a
multi-platform version of that API?

What happens if you just use select to read the file descriptor
associated
with stdin? On Windows iirc, this descriptor is already raw. For Solaris
etc
you can just make it raw with termio calls.