diff --git a/lib/sqlite3/fork_safety.rb b/lib/sqlite3/fork_safety.rb index bdb11797..7fb526d1 100644 --- a/lib/sqlite3/fork_safety.rb +++ b/lib/sqlite3/fork_safety.rb @@ -16,6 +16,7 @@ def _fork end @databases = [] + @mutex = Mutex.new class << self def hook! @@ -23,7 +24,9 @@ def hook! end def track(database) - @databases << WeakRef.new(database) + @mutex.synchronize do + @databases << WeakRef.new(database) + end end def discard