From: Abhijit Sarkar Date: 2013-02-14T12:50:48+09:00 Subject: Ruby Multithreaded producer-consumer problem Hi, I started on Ruby less than a week ago but have already come to appreciate the power of the language. I am trying my hands on a classic producer-consumer problem, implemented as an Orange tree (c.f. http://pine.fm/LearnToProgram/?Chapter=09). The Orange tree grows each year until it dies and produces a random number of Oranges each year (Producer). Oranges can be picked as long there are any on the tree (Consumer). I've got two problems here: 1) The attached code gives me the following exception: /Users/Abhijit/Workspace/eclipse/ruby/learn_to_program/orange_tree.rb:84: warning: instance variable @orange_tree not initialized /Users/Abhijit/Workspace/eclipse/ruby/learn_to_program/orange_tree.rb:84:in `': undefined method `age' for nil:NilClass (NoMethodError) from /Users/Abhijit/Workspace/eclipse/ruby/learn_to_program/orange_tree.rb:45:in `
' 2) I am not sure that the multithreading part is correctly coded. Any help is very much appreciated. I've got myself a couple of books, including "Programming Ruby" and "The Ruby Programming Language" but none of them contain a true "producer-consumer problem". Attachments: http://www.ruby-forum.com/attachment/8127/orange_tree.rb -- Posted via http://www.ruby-forum.com/.