ruby-changes:44912
From: shugo <ko1@a...>
Date: Mon, 5 Dec 2016 20:10:10 +0900 (JST)
Subject: [ruby-changes:44912] shugo:r56985 (trunk): Don't insert an entry to loading_tbl if another thread succeed to load.
shugo 2016-12-05 20:10:05 +0900 (Mon, 05 Dec 2016) New Revision: 56985 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=56985 Log: Don't insert an entry to loading_tbl if another thread succeed to load. If rb_thread_shield_wait() returns Qfalse, the file has been successfully loaded by another thread, so there is no need to insert a new entry into loading_tbl. [ruby-core:78464] [Bug #12999] Modified files: trunk/load.c trunk/test/ruby/test_require.rb Index: load.c =================================================================== --- load.c (revision 56984) +++ load.c (revision 56985) @@ -745,9 +745,6 @@ load_lock(const char *ftptr) https://github.com/ruby/ruby/blob/trunk/load.c#L745 } switch (rb_thread_shield_wait((VALUE)data)) { case Qfalse: - data = (st_data_t)ftptr; - st_insert(loading_tbl, data, (st_data_t)rb_thread_shield_new()); - return 0; case Qnil: return 0; } @@ -759,7 +756,10 @@ release_thread_shield(st_data_t *key, st https://github.com/ruby/ruby/blob/trunk/load.c#L756 { VALUE thread_shield = (VALUE)*value; if (!existing) return ST_STOP; - if (done ? rb_thread_shield_destroy(thread_shield) : rb_thread_shield_release(thread_shield)) { + if (done) { + rb_thread_shield_destroy(thread_shield); + } + else if (rb_thread_shield_release(thread_shield)) { /* still in-use */ return ST_CONTINUE; } Index: test/ruby/test_require.rb =================================================================== --- test/ruby/test_require.rb (revision 56984) +++ test/ruby/test_require.rb (revision 56985) @@ -697,9 +697,9 @@ class TestRequire < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/ruby/test_require.rb#L697 bug7530 = '[ruby-core:50645]' Tempfile.create(%w'bug-7530- .rb') {|script| script.close - assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], <<-INPUT, %w(:ok), [], bug7530, timeout: 20) + assert_in_out_err([{"RUBYOPT" => nil}, "-", script.path], <<-INPUT, %w(:ok), [], bug7530, timeout: 40) PATH = ARGV.shift - THREADS = 2 + THREADS = 4 ITERATIONS_PER_THREAD = 1000 THREADS.times.map { -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/