Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 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
- threads = []
- (1..5).each do |i|
- threads << Thread.new { Thread.current[:output] = `echo Hi from thread ##{i}` }
- end
- threads.each do |t|
- t.join
- puts t[:output]
- end
- puts t.value
- #!/usr/bin/env ruby
- threads = (1..5).collect do |i|
- Thread.new { `echo Hi from thread ##{i}` }
- end
- threads.each do |t|
- puts t.value
- end
- Hi from thread #1
- Hi from thread #2
- Hi from thread #3
- Hi from thread #4
- Hi from thread #5
- a, b, c = [
- Thread.new { "something" },
- Thread.new { "something else" },
- Thread.new { "what?" }
- ].map(&:value)
- a # => "something"
- b # => "something else"
- c # => "what?"
- threads = (1..5).collect do |i|
- Thread.new { `echo x#{i}.bin` }
- end
- threads.each do |t|
- puts t.value
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement