I followed the example from http://www.ruby-doc.org/stdlib/libdoc/monitor/rdoc/index.html and modified the code a bit:
require 'monitor.rb'
buf = []
buf.extend(MonitorMixin)
empty_cond = buf.new_cond
producer = Thread.start do
# producer
line = "produce at #{Time.now}"
#while line
buf.synchronize do
puts "==> #{line}"
buf.push(line)
empty_cond.signal
end
sleep(2)
#line = "produce at #{Time.now}"
#end
end
loop do
buf.synchronize do
empty_cond.wait_while { buf.empty? }
item = buf.shift
puts "got #{item.inspect}"
end
end
I let the program run. Around 5 min later, it throws a "Segmentation fault". Something related to a deadlock?
/Jack