From: "nobu (Nobuyoshi Nakada)" Date: 2013-05-07T16:45:45+09:00 Subject: [ruby-core:54844] [ruby-trunk - Bug #8374][Assigned] race condition when two threads require a gem with a C extension Issue #8374 has been updated by nobu (Nobuyoshi Nakada). Description updated Category set to lib Status changed from Open to Assigned Assignee set to drbrain (Eric Hodel) Seems rubygems specific. ---------------------------------------- Bug #8374: race condition when two threads require a gem with a C extension https://bugs.ruby-lang.org/issues/8374#change-39175 Author: vjoel (Joel VanderWerf) Status: Assigned Priority: Normal Assignee: drbrain (Eric Hodel) Category: lib Target version: ruby -v: ruby 2.0.0p0 (2013-02-24) [i686-linux] Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN =begin Requiring a gem with a C extension seems to be not threadsafe. Any one of the require lines below will frequently (but not always) cause an error like the following: /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require': cannot load such file -- sqlite3 (LoadError) from /usr/local/lib/ruby/site_ruby/2.0.0/rubygems/core_ext/kernel_require.rb:45:in `require' from thread.rb:7:in `block (2 levels) in
' Using one thread avoids the problem. ths = (1..2).map do Thread.new do # require 'msgpack' # require 'yajl' # require 'sequel' # require 'nio4r' require 'sqlite3' end end ths.each {|th| th.join} =end -- http://bugs.ruby-lang.org/