Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
在下面的代码中,我希望'a'打印 1000 行,但它不输出任何内容。没有Thread.new{and },它可以工作。我究竟做错了什么?
'a'
Thread.new{
}
Thread.new{1000.times{puts 'a'}}
尝试
Thread.new{1000.times{puts 'a'}}.join
您创建了一个将打印a1,000 次的线程,但是您会怎么做?如果您的程序在该线程有机会运行之前终止,则不会打印任何内容。
a