From: “Jacek O.” firstname.lastname@example.org
Unfortunelty “gets” block my whole application - the “b” thread waits
until user writes something to the stdin. But I want the b thread not
wait and run at the same time.
This tends to be a problem with Windows ruby. It seems unlikely to be
resolved until Ruby gets native threads (on the horizon with YARV.)
Here’s how I’ve worked around it. If anyone knows a better way, please
if RUBY_PLATFORM =~ /win32/
$win32_console_kbhit = Win32API.new(“msvcrt”, “_kbhit”, , ‘I’)
$win32_console_kbhit.call != 0
sleep(0.1) until console_input_ready?
$stdin.gets # don’t bother to use getc, it also blocks until user
$stdin.gets # it just works, on unix
So you can use nonblocking_stdin_gets in place of $stdin.gets. It’s an
imperfect solution, though. It will be nonblocking until the user
typing. Then it will block until they hit . (Note, I’ve tried
it character-by-character, with $stdin.getc or $stdin.sysread(1), but it
still blocks until the user hits .) There’s probably a way to
the windows console into unbuffered mode, which would improve this
hack (so we could use $stdin.getc in conjunction with
Anyway, hope this helps . . .