Se ho il seguente codice:Come posso restituire un valore da un thread in Ruby?
threads = []
(1..5).each do |i|
threads << Thread.new { `process x#{i}.bin` }
end
threads.each do |t|
t.join
# i'd like to get the output of the process command now.
end
Che cosa devo fare per ottenere l'output del comando processo? Come posso creare un thread personalizzato in modo che io possa realizzare questo?
Vinay, forse puoi dare un'occhiata anche a questo: http://stackoverflow.com/questions/1383470/why-is-this-running-like-it-isnt-threaded – Geo
Molto più semplice restituire semplicemente l'output dal thread e usa 'puts t.value' – Yacoby