a = Thread.new { 5.times { |i| p i; sleep 0.1 } } a.join p 'a' b = Thread.new { 5.times { |k| p k; sleep 0.1 } } b.join p 'b' This will print out 01234a01234b. What I want it to print out is: 001122334a4b.
p 'b' and p 'a' must both be outside of threads. They must execute after corresponding thread is finished. a and b threads must execute concurrently.
How can it be done?