<?xml version="1.0" encoding="UTF-8"?>
<commit>
  <added type="array"/>
  <modified type="array">
    <modified>
      <diff>@@ -12,6 +12,9 @@ module ActiveRecord
 
         # The ConnectionSpecification for this pool
         @spec = spec
+
+        # The mutex used to synchronize pool access
+        @connection_mutex = Monitor.new
       end
 
       def active_connection_name #:nodoc:
@@ -70,7 +73,7 @@ module ActiveRecord
           # Verify the connection.
           conn.verify!(verification_timeout)
         else
-          self.connection = spec
+          self.set_connection spec
           conn = active_connections[name]
         end
 
@@ -82,6 +85,7 @@ module ActiveRecord
         active_connections[active_connection_name] ? true : false
       end
 
+      # Disconnect all connections in the pool.
       def disconnect!
         clear_cache!(@active_connections) do |name, conn|
           conn.disconnect!
@@ -89,16 +93,20 @@ module ActiveRecord
       end
 
       # Set the connection for the class.
-      def connection=(spec) #:nodoc:
+      def set_connection(spec) #:nodoc:
         if spec.kind_of?(ActiveRecord::ConnectionAdapters::AbstractAdapter)
           active_connections[active_connection_name] = spec
         elsif spec.kind_of?(ActiveRecord::Base::ConnectionSpecification)
-          self.connection = ActiveRecord::Base.send(spec.adapter_method, spec.config)
+          self.set_connection ActiveRecord::Base.send(spec.adapter_method, spec.config)
         else
           raise ConnectionNotEstablished
         end
       end
 
+      synchronize :active_connection, :connection, :clear_active_connections!,
+        :clear_reloadable_connections!, :verify_active_connections!, :retrieve_connection,
+        :connected?, :disconnect!, :set_connection, :with =&gt; :@connection_mutex
+
       private
         def clear_cache!(cache, &amp;block)
           cache.each(&amp;block) if block_given?</diff>
      <filename>activerecord/lib/active_record/connection_adapters/abstract/connection_pool.rb</filename>
    </modified>
    <modified>
      <diff>@@ -27,6 +27,8 @@ module ActiveRecord
     @@connection_pools = {}
 
     class &lt;&lt; self
+      # Turning on allow_concurrency basically switches a null mutex for a real one, so that
+      # multi-threaded access of the connection pools hash is synchronized.
       def allow_concurrency=(flag)
         if @@allow_concurrency != flag
           if flag
@@ -37,7 +39,7 @@ module ActiveRecord
         end
       end
 
-      # for internal use only
+      # for internal use only and for testing
       def active_connections #:nodoc:
         @@connection_pools.inject({}) do |hash,kv|
           hash[kv.first] = kv.last.active_connection</diff>
      <filename>activerecord/lib/active_record/connection_adapters/abstract/connection_specification.rb</filename>
    </modified>
    <modified>
      <diff>@@ -18,7 +18,7 @@ class Module
       raise ArgumentError, &quot;Synchronization needs a mutex. Supply an options hash with a :with key as the last argument (e.g. synchronize :hello, :with =&gt; :@mutex).&quot;
     end
 
-    methods.each do |method|
+    methods.flatten.each do |method|
       aliased_method, punctuation = method.to_s.sub(/([?!=])$/, ''), $1
       if instance_methods.include?(&quot;#{aliased_method}_without_synchronization#{punctuation}&quot;)
         raise ArgumentError, &quot;#{method} is already synchronized. Double synchronization is not currently supported.&quot;
@@ -26,7 +26,7 @@ class Module
       module_eval(&lt;&lt;-EOS, __FILE__, __LINE__)
         def #{aliased_method}_with_synchronization#{punctuation}(*args, &amp;block)
           #{with}.synchronize do
-            #{aliased_method}_without_synchronization#{punctuation}(*args,&amp;block)
+            #{aliased_method}_without_synchronization#{punctuation}(*args, &amp;block)
           end
         end
       EOS</diff>
      <filename>activesupport/lib/active_support/core_ext/module/synchronization.rb</filename>
    </modified>
  </modified>
  <removed type="array"/>
  <parents type="array">
    <parent>
      <id>50cd4bdc99ebaf3ac879e4e7fea43c5b55ca5f68</id>
    </parent>
  </parents>
  <author>
    <name>Nick</name>
    <email>nick@nicksieger.com</email>
  </author>
  <url>http://github.com/rails/rails/commit/cab76ce6ac2983f59451e2d53b23746a2873aea0</url>
  <id>cab76ce6ac2983f59451e2d53b23746a2873aea0</id>
  <committed-date>2008-08-29T12:12:09-07:00</committed-date>
  <authored-date>2008-04-19T12:42:56-07:00</authored-date>
  <message>Add synchronization to connection pool also</message>
  <tree>9aeb8c88ac13d353660d147fb82e6b865700f45a</tree>
  <committer>
    <name>Nick Sieger</name>
    <email>nick@nicksieger.com</email>
  </committer>
</commit>
