From: "ara.t.howard" Date: 2007-09-11T13:43:57+09:00 Subject: Re: Thread deadlock problem On Sep 10, 2007, at 9:35 PM, wimxa@yahoo.com wrote: > require 'thread' > > mutex = Mutex.new > c_produce = ConditionVariable.new > c_consume = ConditionVariable.new > full = false > t1 = Thread.new do > while true > mutex.synchronize do > c_produce.wait mutex while full > print 'F' > full = true > c_consume.signal > end > #sleep 0.001 > end > end > t2 = Thread.new do > while true > mutex.synchronize do > c_consume.wait mutex while !full > print '.' > full = false > c_produce.signal > end > end > end > t1.join > t2.join it seems like you are making if very hard on yourself. why not something like this: cfp:~ > cat a.rb require 'thread' q = SizedQueue.new 42 producer = Thread.new do loop do q.push Time.now.to_f end end consumer = Thread.new do loop do p(( data = q.pop )) end end producer.join consumer.join ?? if you really want to roll your own stuff check out the code in thread.rb - the Queue and SizedQueue classes are basically the code you are writing above. cheers. a @ http://drawohara.com/ -- we can deny everything, except that we have the possibility of being better. simply reflect on that. h.h. the 14th dalai lama