0

In the following code, I expect 1000 lines of 'a' to be printed, but it does not output anything. Without Thread.new{ and }, it works. What am I doing wrong?

Thread.new{1000.times{puts 'a'}}

2 Answers 2

3

try

Thread.new{1000.times{puts 'a'}}.join
1
  • Thanks. Your answer adds additional information on top of David's, and is helpful. I accepted David's because it was earlier.
    – sawa
    Feb 2, 2012 at 20:08
2

You create a thread that will print a 1,000 times, but then what do you do? If your program terminates before that thread gets a chance to run, nothing will be printed.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.