<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -7,16 +7,6 @@ class Object
     class MustImplementDisposeError &lt; StandardError
     end
     
-    @size = 4
-    
-    def self.size
-      @size
-    end
-    
-    def self.size=(value)
-      @size = size
-    end
-    
     def self.included(target)
       target.extend(ClassMethods)
     end
@@ -28,10 +18,12 @@ class Object
     class Pools
       
       attr_reader :type
+      attr_accessor :size
       
-      def initialize(type)
+      def initialize(type, size = 4)
         @type = type
-        @pools = Hash.new { |h,k| h[k] = Pool.new(@type, k) }
+        @size = size
+        @pools = Hash.new { |h,k| h[k] = Pool.new(@size, @type, k) }
       end
       
       def flush!
@@ -51,7 +43,8 @@ class Object
       
         attr_reader :type, :available, :reserved
       
-        def initialize(type, initializer)
+        def initialize(size, type, initializer)
+          @size = size
           @type = type
           @initializer = initializer
           @lock = Mutex.new
@@ -60,35 +53,54 @@ class Object
         end
       
         def flush!
-          reserved.each do |entry|
-            entry.release
-          end
+          @lock.synchronize do
+            reserved.each do |instance|
+              if @reserved.delete?(instance)
+                @available &lt;&lt; instance
+              end
+            end
         
-          available.each do |entry|
-            entry.dispose
-          end
+            available.each do |instance|
+              instance.dispose
+            end
           
-          @available = []
-          @reserved = Set.new
+            @available = []
+            @reserved = Set.new
+          end
         end
         
         def new
-          instance = nil
-
-          @lock.synchronize do          
-            unless @available.empty?
-              instance = @available.pop
-            else
-              instance = @type.allocate
-              instance.send(:initialize, *@initializer)
-              at_exit { instance.dispose }
-              instance.instance_variable_set(&quot;@__pool&quot;, self)
+          if @available.empty?
+            @lock.synchronize do
+              instance = nil
+              
+              if @available.empty?
+                if @reserved.size &lt; @size
+                  instance = @type.allocate
+                  instance.send(:initialize, *@initializer)
+                  at_exit { instance.dispose }
+                  instance.instance_variable_set(&quot;@__pool&quot;, self)
+                else
+                  # until(instance) do
+                    # TODO: Need to wait for an instance to become available,
+                    # but to do that we need to not use a synchronization block.
+                  # end
+                  
+                  instance = @type.allocate
+                  instance.send(:initialize, *@initializer)
+                  at_exit { instance.dispose }
+                  instance.instance_variable_set(&quot;@__pool&quot;, self)
+                end
+              else
+                instance = @available.pop
+              end
+              
+              @reserved &lt;&lt; instance
+              instance
             end
-
-            @reserved &lt;&lt; instance
+          else
+            aquire_instance!
           end
-
-          return instance
         end
 
         def release(instance)
@@ -101,7 +113,16 @@ class Object
         end
         
         private
-        def synchronize
+        def aquire_instance!
+          instance = nil
+          
+          @lock.synchronize do
+            instance = @available.pop
+            raise StandardError.new(&quot;Concurrency Error!&quot;) unless instance
+            @reserved &lt;&lt; instance
+          end
+          
+          instance
         end
       end
     end</diff>
      <filename>data_objects/lib/data_objects/support/pooling.rb</filename>
    </modified>
    <modified>
      <diff>@@ -1,4 +1,5 @@
 require File.join(File.dirname(__FILE__), '..', '..', 'lib', 'data_objects', 'support', 'pooling')
+require 'timeout'
 
 describe &quot;Object::Pooling&quot; do
   
@@ -21,7 +22,22 @@ describe &quot;Object::Pooling&quot; do
   end
   
   it &quot;should have a max pool-size&quot; do
-    Object::Pooling::size.should == 4
+    pending
+    
+    Thing::pools.size.should == 4
+    
+    Thing.new('Grumpy')
+    Thing.new('Grumpy')
+    Thing.new('Grumpy')
+    Thing.new('Grumpy')
+    
+    thread = Thread.new { Thing.new('Grumpy') }
+    
+    lambda do
+      Timeout::timeout(1) { thread.join }
+    end.should raise_error(Timeout::Error)
+    
+    Thing::pools.flush!
   end
   
   it &quot;should respond to ::new and #release&quot; do
@@ -83,5 +99,7 @@ describe &quot;Object::Pooling&quot; do
     Thing::pools['bob'].flush!
   end
   
-  it &quot;should dispose idle available objects&quot;
+  it &quot;should dispose idle available objects&quot; do
+    pending
+  end
 end
\ No newline at end of file</diff>
      <filename>data_objects/spec/support/pooling_spec.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>ba398122f154b4a5186f6ad687ad1adb5a936919</id>
    </parent>
  </parents>
  <author>
    <name>Sam Smoot</name>
    <email>ssmoot@gmail.com</email>
  </author>
  <url>http://github.com/sam/do/commit/6dc7ddaac0a48e20d09c3aa93f66b485b06d902c</url>
  <id>6dc7ddaac0a48e20d09c3aa93f66b485b06d902c</id>
  <committed-date>2008-05-07T21:51:44-07:00</committed-date>
  <authored-date>2008-05-07T21:51:44-07:00</authored-date>
  <message>Pretty close now. Need to play around with the Mutex a bit and should be basically done.</message>
  <tree>f20a82f205f4607fdf936dc2e0bfd3e32027918a</tree>
  <committer>
    <name>Sam Smoot</name>
    <email>ssmoot@gmail.com</email>
  </committer>
</commit>
