From: Brian Candler Date: 2010-04-07T23:45:22+09:00 Subject: Re: modifying a Hash in one process when .each is running in another 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 via http://www.ruby-forum.com/.