From: "Jesús Gabriel y Galán" Date: 2013-03-16T20:44:09+09:00 Subject: Re: control the concurrent thread numbers On Sat, Mar 16, 2013 at 12:13 PM, Ken Paul wrote: > Hi, > > I'd like to run total 10 threads concurrently, but from the printed > result I can see there is only one thread is running, not 10. What is > the issue? > > thread_limit = 10 > @array = (1..100).to_a > > while @array.size > 0 > if Thread.list.size < thread_limit > Thread.new { > @array.shift > }.join > end > puts Thread.list.size > end > The thread that calls join suspends its execution until the joined thread finishes. So when join returns in your code, the thread that did @array.shift doesn't exist anymore. If you want several threads to shift from the array "simultaneously", you have to take care about synchronizing access to the shared array, though. What are you really trying to accomplish? Jesus.