--0015175d026c1072770477168599 Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: quoted-printable On Thu, Oct 29, 2009 at 8:56 AM, Marc Hoeppner <marc.hoeppner / molbio.su.se>wrote: > Hi, > > I've been reading around a bit but couldn't find a solution that worked, > so here goes: > > I am running ruby 1.8 and want to make full use of a quad core CPU > (64bit, Ubuntu) in a task that lends itself to multithreading/multicore > use. > > It's basically an array of objects that are each use in a fairly CPU > intensive job, so I figured I could have 4 of them run at the same time > , one on each CPU. > > BUT... > > The only reasonably understandably suggestion looked something like: > > ---- > threads = 4 > my_array = [something_here] > > threads.times do > Process.fork(a_method(my_array.shift)) > end > > my_array.each do |object| > Process.wait(0) > Process.fork(a_method(object)) > end > --- > > But this still only used one CPU (and looks a bit ugly..). Is that some > limitation of ruby (v 1.8 specifically) or am I doing something wrong? > > Cheers, > > Marc > -- > Posted via http://www.ruby-forum.com/. > > You are going to want Ruby 1.9 for this. In 1.8 threads are "green", basically they only exists as threads inside the VM so you still only hit one core and any blocking system I/O will block all of your threads. -- "Hey brother Christian with your high and mighty errand, Your actions speak so loud, I canÃÕ hear a word youÃÓe saying." -Greg Graffin (Bad Religion) --0015175d026c1072770477168599--