From: 7stud -- Date: 2007-10-09T17:35:38+09:00 Subject: Re: thread problem..... 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/.