From: Srinivas JONNALAGADDA Date: 2006-07-29T18:45:05+09:00 Subject: Re: ruby threads? the point? On Sat, 2006-07-29 at 06:18 +0900, Eric Armstrong wrote: > Below. And now that I'm at work, rather than > at home, I've been able to determine that it > works as expected on my Solaris box, but fails > on Windows XP. (There, the display only updates > after pressing spacebar or some other key.) > Here is an improvisation to your code. This automatically exits at the end of the set timer, rather than wait for a 'q/Q' from the user. Greetings, JS ---- require 'curses' require 'thwait' count = ARGV[0] ? ARGV[0].to_i : 100 Curses.addstr "I am going to count #{count}. Press 'q' or 'Q' to exit.\n" Curses.refresh threads = ThreadsWait.new timer_thread = Thread.new do count.downto(1) do |i| Curses.addstr(".") Curses.refresh sleep 1 end end threads.join_nowait timer_thread wait_thread = Thread.new do while true c = Curses.getch case c when ?q, ?Q return true end end end threads.join_nowait wait_thread begin threads.next_wait ensure Thread.kill(timer_thread) Thread.kill(wait_thread) end