Хабр Курсы для всех
РЕКЛАМА
Практикум, Хекслет, SkyPro, авторские курсы — собрали всех и попросили скидки. Осталось выбрать!
Thread.list.each { |t| t.join if t != Thread.current }
requests = ThreadGroup.new
page_to_fetch.each do |page|
requests.add Thread.new(page_to_fetch) do |url|
# …
end
end
Многопоточность в RubyвRuby многопоточность!
Prior to Ruby 1.9, these were implemented as so-called green threads — threads were switched totally within the interpreter. In Ruby 1.9, threading is now performed by the operating system. This is an improvement, but not quite as big an improvement as you might want. Although threads can now take advantage of multiple processors (and multiple cores in a single processor), there’s a major catch. Many Ruby extension libraries are not thread safe (because they were written for the old threading model). So, Ruby compromises: it uses native operating system threads but operates only a single thread at a time. You’ll never see two threads in the same application running Ruby code truly concurrently. (You will, however, see threads busy doing (say) I/O while another thread executes Ruby code. That’s part of the point....)
Многопоточность в Ruby