以下效率低下吗?我想将几乎所有资源分配给线程,但我想知道在这种情况下这个循环是否会占用大量的CPU时间。
谢谢!
threads = create_threads #method that returns an Array of Threads
loop do
alive = false
threads.each do |thread|
if thread.alive?
alive = true
end
end
break unless alive
end
答案 0 :(得分:3)
threads.each &:join
my_thread.join
会在my_thread
退出后立即返回。
答案 1 :(得分:2)
threads.each do |thread|
thread.join
end