3 # $Id: prodcons.ruby,v 1.3 2005-06-10 00:57:22 igouy-guest Exp $
4 # http://www.bagley.org/~doug/shootout/
10 access
= ConditionVariable
.new
11 count
= data = consumed
= produced
= 0
12 consumer
= Thread
.new
do
16 while count
== 0 do access
.wait(mutex
) end
22 if i
== n
then break end
25 producer
= Thread
.new
do
28 while count
== 1 do access
.wait(mutex
) end
38 puts
"#{produced} #{consumed}"
41 main(Integer(ARGV.shift
|| 1))