From: Tony Arcieri Date: 2013-02-14T13:16:07+09:00 Subject: Re: Ruby Multithreaded producer-consumer problem --bcaec54ee3741e612404d5a7837d Content-Type: text/plain; charset=ISO-8859-1 You might take a look at Celluloid: http://celluloid.io/ On Wed, Feb 13, 2013 at 7:50 PM, Abhijit Sarkar wrote: > 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/. > > -- Tony Arcieri --bcaec54ee3741e612404d5a7837d Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
You might take a look at Celluloid:



On Wed, Feb 13, 20= 13 at 7:50 PM, Abhijit Sarkar <lists@ruby-forum.com> wrot= e:
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.
h= ttp://pine.fm/LearnToProgram/?Chapter=3D09). 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=
`<class:Worker>': undefined method `age' for nil:NilClass
(NoMethodError)
=A0 from
/Users/Abhijit/Workspace/eclipse/ruby/learn_to_program/orange_tree.rb:45:in=
`<main>'

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 Langu= age" 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/.




-- Tony Arcieri
--bcaec54ee3741e612404d5a7837d--