"Thomas A. Reilly" <w3gat / bellsouth.net> wrote:

> I want to use threads to do one process and also wait on any keyboard input.
> The sample of code I've included blocks indefinately.

> I'd appreciate a bit of help.

> The program ought to print out START every second except when something is
> entered by the keyboard then that should be printed till the next keyboard
> entry.  But it just hangs up.

> $g = "START\n"
> s1 = Thread.new {
>         loop {
>                 sleep(2)
>                 $g = gets
>         }
> }
> s2 = Thread.new {
>         loop {
>                 sleep(1)
>                 print $g
>         }
> }
> s1.join
> s2.join



$stdout.sync = true

- at the top to prevent your output hiding in a buffer.

Here, the '$g = gets' in s1 stops the s2 thread until fed.



daz
### ruby 1.7.3 (2002-11-17) [i386-mswin32]