From: Russell Fulton Date: 2009-10-01T08:22:26+09:00 Subject: Monitors on data structures Hi I am trying to use monitors for the first time in ruby. I am familiar with the concept but am having some problems making things work. Background: I have a program that uses nmap-parser to parse large nmap scans and uses the call back to deliver results for each host. The call back is threaded. I want to build lists of IP addresses for further investigation from the callback routine. I have made a class AddressList: class AddressList < Array include MonitorMixin def initialise # redundant ? super end def <<(addr) synchronise do # make sure we don't clobber another thread super( addr ) end end end we need to protect the push code so that to threads don't collide so I put a synchronise block around it. What appears to happen is that the code never exits the synchronise block. puts before the block get executed but ones after do not and nothing is ever added to the list. Clearly I'm missing something. The callback routine: callback = proc do |host| return unless host.status == 'up' host.scripts do |script| s = script.output.gsub(/\n/, ':') next if s =~ / 2008 R2|ERROR/; next unless s =~ /Vista|2008/ $addresses << host.addr end # scripts schedule if $addresses.size > BATCH_SIZE end yes, I'm looking for machines running smb2 to get them before the worm does :) BTW I do have this program working without treads but I want to know why this does not work ! Russell -- Posted via http://www.ruby-forum.com/.