From: Ken Paul Date: 2013-03-16T23:24:15+09:00 Subject: Re: control the concurrent thread numbers "Jesús Gabriel y Galán" wrote in post #1101925: > 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? You are right, I'm trying to consume the array simultaneously. But after I move the join out of loop, it still has problem. How to fix it? threads = [] mut = Mutex.new while @all.size > 0 while Thread.list.size < thread_number threads << Thread.new { mut.sychronize do @all.shift end } end end threads.each {|t| t.join} -- Posted via http://www.ruby-forum.com/.