Reputation: 33
Is it possible to create and execute multiple threads at a same time?
for eg.
to print "a" on screen twice but "instantly" at a same time, I need this lines:
t1=Thread.new{print "a"}
t2=Thread.new{print "a"}
t1.join
t2.join
but what if i want to print "a" 50 times on screen instantly without typing thread.new 50 times? How can i do this, creating and executing 50 threads instantly, please help.
Upvotes: 1
Views: 522
Reputation: 58234
Perhaps you could use an array:
threads = Array.new
50.times { threads << Thread.new { print "a" } }
50.times { threads.pop.join }
Upvotes: 1