On Oct 12, 2007, at 5:51 PM, Jon Handler wrote:

>
> 1. Open the file
> 2. Create 5 threads
>
> Each thread should read a line of the file and process it, but no 2
> threads should get the same line.
>

cfp:~ > cat a.rb
require 'thread'

q = Queue.new

threads = [] and 5.times{ threads << Thread.new{ puts q.pop } }

open(__FILE__){|fd| fd.each{|line| q.push line} }

threads.map{|t| t.join}


cfp:~ > ruby a.rb
require 'thread'

q = Queue.new

threads = [] and 5.times{ threads << Thread.new{ puts q.pop } }



a @ http://codeforpeople.com/
--
it is not enough to be compassionate.  you must act.
h.h. the 14th dalai lama