public
Description: Ruby Thread Pool
Homepage:
Clone URL: git://github.com/fizx/thread_pool.git
name age message
file .gitignore Wed Sep 24 09:39:11 -0700 2008 remove doc from repo [Kyle Maxwell]
file CHANGELOG Sat Sep 27 11:57:25 -0700 2008 logging [Kyle Maxwell]
file LICENSE Wed Sep 24 09:40:51 -0700 2008 mit license [Kyle Maxwell]
file README Thu Nov 20 11:48:05 -0800 2008 fix readme formatting bug [fizx]
file Rakefile Wed Sep 24 09:36:12 -0700 2008 initial release [Kyle Maxwell]
directory lib/ Sat Sep 27 11:57:25 -0700 2008 logging [Kyle Maxwell]
directory test/ Wed Sep 24 20:59:54 -0700 2008 prevent scope gotchas [Kyle Maxwell]
file thread_pool.gemspec Sat Sep 27 11:57:25 -0700 2008 logging [Kyle Maxwell]
README
This code is still pretty early, and not yet used in production.  That said, I am interested in feedback.  You can send 
me a message on GitHub's internal messaging system ( http://github.com/inbox/new/fizx ).

A simple executor-style ThreadPool for Ruby (with tests, yay!)

Usage:

  require "rubygems"
  require "thread_pool"
  pool = ThreadPool.new(threads = 10)
  pool.execute { puts "I'm writing from a thread" }
  pool.join
  
It's often useful to make sure that the properties of Ruby's blocks don't bite you.  The following code will usually 
print three nils, because n keeps changing.

  pool = ThreadPool.new(threads = 10)
  numbers = [1, 2, 3]
  while n = numbers.shift
    pool.execute { puts n.inspect }
  end
  pool.join
  
Passing arguments to execute avoids this. i.e.:

  pool = ThreadPool.new(threads = 10)
  numbers = [1, 2, 3]
  while n = numbers.shift
    pool.execute(n) {|local| puts local.inspect }
  end
  pool.join