From: Nathan Date: 2010-04-07T23:59:18+09:00 Subject: Re: modifying a Hash in one process when .each is running in another Sorry, that should read "it's source has become unavailable". Obviously the object itself is still there!!! On Apr 7, 3:53 pm, Nathan wrote: > > Do you really want generate_list_objects to run 4 times uselessly while > > the test suite runs the original set of tests? > > I think you've misunderstood... sorry if I wasn't clear. Perhaps > naming the method test was a bad idea. I don't mean test as in unit > test or whatever, I mean something completely different. If an object > is no longer on the list returned by generate_list_of_objects, that > means it has become unavailable, and running test won't accomplish > anything meaningful. That's why I'm interested in keeping the list as > up-to-date as possible. > > On Apr 7, 3:45 pm, Brian Candler wrote: > > > > > Nathan Macinnes wrote: > > > Thanks for the clarification... My application is network based, and > > > some operations take several seconds. generate_list_of_objects takes > > > anything between 2 and 15 seconds, so I wouldn't like to have my whole > > > program on hold while that's happening. Each test process takes a few > > > seconds too, so if the object is no longer on the list, it isn't a > > > particularly bad thing if test tries to run, but it'll take up a lot > > > of time unnecessarily. > > > Let's say generate_list_objects takes 15 seconds, and the test suite > > (iterating the objects) takes 60 seconds. Do you really want > > generate_list_objects to run 4 times uselessly while the test suite runs > > the original set of tests? > > > Similarly, if the test suite takes 15 seconds and generate_list_objects > > takes 60 seconds, do you want to run the test suite 4 times identically > > with the first set of objects? > > > If not, but rather you want to run the test suite exactly once for each > > set of data, then you should synchronize them. How about this > > (untested): > > > require 'thread' > > cmd = Queue.new > > res = Queue.new > > tester = Thread.new do > >   while myHash = cmd.pop > >     myHash.each { ... } > >     res.push [myHash, :ok] > >   end > > end > > > q.push MyClass.generate_list_of_objects > > while Time.now < time_to_finish > >   q.push MyClass.generate_list_of_objects > >   res.pop > > end > > res.pop > > q.push nil > > tester.wait > > -- > > Posted viahttp://www.ruby-forum.com/.