rails中的'deadlock detected'错误

时间:2010-10-09 15:12:58

标签: ruby-on-rails ruby multithreading deadlock

我的代码中出现死锁检测错误,并且不明白原因。

有人可以告诉我,我做错了什么吗?

#!/usr/bin/ruby
ENV['RAILS_ENV'] = ARGV.first || ENV['RAILS_ENV'] || 'development'  
require File.expand_path(File.dirname(__FILE__) + "/config/environment")

mutex = Mutex.new
threads = []
1.upto(10) do |i|
  threads << Thread.new(i) do |id|
    mutex.synchronize do
      # here I want to take 1 record from "class Product < ActiveRecord::Base"
      Product.first
    end
    # and to do here some stuff with it
    # ...
    # but all I get is
    # ./sandbox.rb:15:in `join': deadlock detected (fatal)
  end
end
threads.each { |thread| thread.join }

我使用rails 3和ruby 1.9.2

0 个答案:

没有答案