'deadlock detected' error in rails

不打扰是莪最后的温柔 提交于 2019-12-23 22:02:17

问题


I have deadlock detected error in my code and don't understand why.

Could someone please tell me what am I doing wrong?

#!/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 }

I use rails 3 and ruby 1.9.2

来源:https://stackoverflow.com/questions/3896096/deadlock-detected-error-in-rails

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!