From 0d51d86dee54b1fad1cc588d0be025c9e4cdf1bc Mon Sep 17 00:00:00 2001 From: Martin Kihlgren Date: Wed, 2 Jul 2008 10:02:28 +0200 Subject: [PATCH] Fixed the deadlock in pooling.rb. * Used Monitor instead of Mutex, since Monitor is reentrant. * Made sure all locks were acquired in the same order to kill the deadlock. --- lib/extlib/pooling.rb | 8 ++++---- 1 files changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/extlib/pooling.rb b/lib/extlib/pooling.rb index 3e131de..7505a8d 100644 --- a/lib/extlib/pooling.rb +++ b/lib/extlib/pooling.rb @@ -1,5 +1,5 @@ require 'set' -require 'thread' +require 'monitor' module Extlib # ==== Notes @@ -61,7 +61,7 @@ module Extlib end def self.lock - @lock ||= Mutex.new + @lock ||= Monitor.new end class CrossPoolError < StandardError @@ -79,8 +79,8 @@ module Extlib alias __new new end - @__pools = Hash.new { |h,k| __pool_lock.synchronize { h[k] = Pool.new(target.pool_size, target, k) } } - @__pool_lock = Mutex.new + @__pools = Hash.new { |h,k| Pooling.lock.synchronize { __pool_lock.synchronize { h[k] = Pool.new(target.pool_size, target, k) } } } + @__pool_lock = Monitor.new def self.__pool_lock @__pool_lock -- 1.5.5.1