title: How to run multiple threads at the same time in ruby while working with a file?
body: <p>I've been messing around with Ruby and threading a little bit today. I have a list of proxies that I want to check. Assuming a timeout of 10 seconds going through a very large list of proxies will take many hours if I write something that goes like:</p>
  
  <pre><code>  proxies.each do |proxy|
     check_proxy(proxy)
    end
  </code></pre>
  
  <p>My first problem with trying to figure out threads is how to START multiple at the same exact time. I found a neat little snippet of code online:</p>
  
  <pre><code>for page in pages
    threads &lt;&lt; Thread.new(page) { |myPage|
  
      puts "Fetching: #{myPage}\n"
      doc = Hpricot(open(myPage.to_s)).to_s
      puts "Got #{myPage}:  #{doc.size}"
    }
  end
  </code></pre>
  
  <p>Seems to work nicely as far as starting them all at the same time. So now I can... start checking all 7 thousand records at the same time? </p>
  
  <p>How do I go to a file, take out a line for each thread, run a batch of like 20 and repeat the process? </p>
  
  <p>Can I run a while loop that in turn starts 20 threads at the same (which remove lines from a file) and keeps going until the file is blank?</p>
  
  <p>I'm a little weak on the logic of what I'm supposed to do.</p>
  
  <p>Thanks guys!</p>
  
  <p>PS. </p>
  
  <p>Another thought: Will there be file access issues if 20 workers are constantly messing with it randomly? What would be a good way around that if this is so?</p>