From: Ken Bloom Date: 2009-10-01T23:08:48+09:00 Subject: Re: Monitors on data structures On Thu, 01 Oct 2009 08:22:26 +0900, Russell Fulton wrote: > 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 synchronize is spelled with a z. You misspelled it in the example you posted here. Is it possible that you misspelled it in your actual code, and the NoMethodError is being raised in a place where it doesn't generate output to alert you to the problem? -- Chanoch (Ken) Bloom. PhD candidate. Linguistic Cognition Laboratory. Department of Computer Science. Illinois Institute of Technology. http://www.iit.edu/~kbloom1/