Потоки реализуются с помощью класса Thread
#!/usr/bin/ruby
# Treads
n = %w(String1 String2 String3)
threads = []
c = 1
for i in n
threads << Thread.new(i) { |str|
# set thread variable
Thread.current["counter"] = c
sleep(rand(10));
puts str
}
c += 1
end
# wait for threads
threads.each { |x|
x.join
puts "Done "<< x["counter"].to_s
}
# sleep(20);
Ruby Справочник v0.05 © 2007-2024 Igor Salnikov aka SunDoctor