any idea why this script slows downs drastically as it runs and seems to leak
memory?


require 'sync'

class Switch
   ON, OFF, NEITHER = true, false, nil

   def initialize state = OFF
     extend Sync_m
     @state = NEITHER
     @observers = []
   end

   def on!
     synchronize(:EX){
       warn 'on!'
       @state = ON
       notity_observers
     }
   end

   def off!
     synchronize(:EX){
       warn 'off!'
       @state = OFF
       notity_observers
     }
   end

   def notity_observers
     synchronize(:SH){
       @observers.each do |o|
         o.notify @state
       end
     }
   end

   def add_observer o
     synchronize(:EX){
       @observers << o
     }
   end
end

class SwitchToggle
   def initialize switch
     @switch = switch
     @switch.add_observer self
   end
   def notify of
     case of
       when Switch::ON
         Thread.new{ @switch.off! }
       when Switch::OFF
         Thread.new{ @switch.on! }
       else
         raise of.to_s
     end
   end
end

switch = Switch.new
toggle = SwitchToggle.new switch

switch.on!

STDIN.gets

-a
-- 
suffering increases your inner strength.  also, the wishing for suffering
makes the suffering disappear.
- h.h. the 14th dali lama