From: Michael Bevilacqua-Linn Date: 2007-10-09T23:00:35+09:00 Subject: Re: thread problem..... ------=_Part_5905_20481838.1191938429112 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit Content-Disposition: inline Um, All you're doing is creating threads and putting them to sleep... You're not doing any actual work. What are you getting at exactly? MBL On 10/9/07, 7stud -- wrote: > > Michael Bevilacqua-Linn wrote: > > 1.) The only way threads get you a speedup is when you write your code > > in > > such a way that sections of it can be executed in parallel so you can > > take > > advantage of multiple cores (or processors). > > > > 2.) The current version of Ruby only supports green threads anyhow. So > > even > > if you did have multiple cores, you wouldn't get a speedup. > > > > MBL > > Then perhaps you could explain the output of this program: > > require 'rtiming' #a simple program that times methods > > def test1 > threads = [] > > 2.times do |i| > threads[i] = Thread.new do > sleep(2) > puts "task #{i+1} finished" > end > end > > threads.each do |t| > t.join > end > end > > def test2 > sleep(2) > puts "task 1 finished" > > sleep(2) > puts "task 2 finished" > end > > puts timer(:test1, 1) > puts timer(:test2, 1) > > > --output:--- > task 2 finished > task 1 finished > Method exec time(1 loops): 2.010791 total > task 1 finished > task 2 finished > Method exec time(1 loops): 4.000226 total > -- > Posted via http://www.ruby-forum.com/. > > ------=_Part_5905_20481838.1191938429112--