| 1 | #!/usr/bin/env ruby
|
| 2 |
|
| 3 | $:.push File.join( File.dirname(__FILE__), "..", "..", "lib" )
|
| 4 |
|
| 5 | require 'dramatis/actor'
|
| 6 |
|
| 7 | class PingPong
|
| 8 |
|
| 9 | include Dramatis::Actor
|
| 10 |
|
| 11 | def initialize name
|
| 12 | @name = name
|
| 13 | end
|
| 14 |
|
| 15 | def pingpong count, partner
|
| 16 | if count == 0
|
| 17 | puts "#{@name}: done"
|
| 18 | else
|
| 19 | if count % 500 == 0 or count % 500 == 1
|
| 20 | puts "#{@name}: pingpong #{count}"
|
| 21 | end
|
| 22 | release( partner ).pingpong count-1, self
|
| 23 | end
|
| 24 | # sleep 0.001
|
| 25 | end
|
| 26 |
|
| 27 | end
|
| 28 |
|
| 29 | ping = PingPong.new "ping"
|
| 30 | pong = PingPong.new "pong"
|
| 31 |
|
| 32 | ping.pingpong ARGV[0].to_i, pong
|
| 33 |
|