Bugs item #6069, was opened at 2006-10-09 09:45
You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6069&group_id=426

Category: Standard Library
Group: 1.8.4
Status: Open
Resolution: None
Priority: 3
Submitted By: Chris Ward (piquant)
Assigned to: Nobody (None)
Summary: Monitor fails when used in classes supporting constructors

Initial Comment:
The following code works:

require 'monitor'

class MonitorBug
    include MonitorMixin
    
    def AddObject(object)
        synchronize do
          puts object.to_s
        end
    end
end

t = MonitorBug.new
t.AddObject(1)



But if I include a constructor, it fails:

class MonitorBug
    include MonitorMixin

    def initialize
      @count = 0
    end
    
    def AddObject(object)
        synchronize do  #fails here
          puts object.to_s
        end
    end
end

t = MonitorBug.new
t.AddObject(1)



In monitor.rb, the offending code is:

def mon_enter
  Thread.critical = true
  mon_acquire(@mon_entering_queue)
  @mon_count += 1   #fails here because @mon_count is nil
  Thread.critical = false
end

----------------------------------------------------------------------

You can respond by visiting: 
http://rubyforge.org/tracker/?func=detail&atid=1698&aid=6069&group_id=426