Jacek Olszak <jacekolszak / o2.pl> wrote: > Hi everyone... > > I've a simple question - how can I write an application with two > threads, where first thread reads the user input. I want both threads > to run SIMULTANEOUSLY. > So .. here is my code: > > a=Thread.new do > $stdin.gets > end > > b=Thread.new do > 5.times do > print "b" > $stdout.flush > Thread.pass > end > end > > a.join > b.join > > 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. > > Thanks > Jacek I'm not sure what you're up to in the end but I'd start with commenting Thread.pass. Ruby normally schedules threads automatically and thus you usually don't need Thread.pass. And btw, you can do $stdout.sync=true - which removes the necessity of invoking flush. Ah, and another note: the first thread blocks the whole app until you enter something simply because it's joined on. The main thread won't exit until you enter something. HTH robert