开发者

How to efficiently supervise Ruby Threads?

开发者 https://www.devze.com 2022-12-20 02:30 出处:网络
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 l开发者_开发技巧ot of CPU time.

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 l开发者_开发技巧ot 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 &:join

my_thread.join returns as soon as my_thread exits.


threads.each do |thread|
  thread.join
end
0

精彩评论

暂无评论...
验证码 换一张
取 消