当前位置: 动力学知识库 > 问答 > 编程问答 >

multithreading - How to efficiently supervise Ruby Threads?

问题描述:

Is the following inefficient? I want to allocate nearly all resources to threads but I'm wondering if in this case this loop will consume a lot of CPU time.

Thanks!

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

网友答案:
threads.each do |thread|
  thread.join
end
网友答案:
threads.each &:join

my_thread.join returns as soon as my_thread exits.

分享给朋友:
您可能感兴趣的文章:
随机阅读: