diff options
| author | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-30 10:52:04 +0000 |
|---|---|---|
| committer | usa <usa@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2017-06-30 10:52:04 +0000 |
| commit | 8f01d618e8e4960265696f0ea11cbcbb941fc2ce (patch) | |
| tree | 8b1f4accc01c263fcbde98f1faf73ad8e2cceca7 | |
| parent | d25b9efdaa40041a894206e54a3e3ee83b2f106b (diff) | |
merge revision(s) 58587,58588: [Backport #13526]
variable.c: cleanup waitq upon thread death
* variable.c (autoload_reset): use idempotent list_del_init
(autoload_sleep): moved code from rb_autoload_load
(autoload_sleep_done): cleanup for use with rb_ensure
(rb_autoload_load): ensure list delete happens in case the
thread dies during sleep
* test/ruby/bug-13526.rb: new script for separate execution
* test/ruby/test_autoload.rb (test_bug_13526): new test
[ruby-core:81016] [Bug #13526]
* properties.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_3@59219 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
| -rw-r--r-- | ChangeLog | 15 | ||||
| -rw-r--r-- | test/ruby/bug-13526.rb | 20 | ||||
| -rw-r--r-- | test/ruby/test_autoload.rb | 5 | ||||
| -rw-r--r-- | variable.c | 40 | ||||
| -rw-r--r-- | version.h | 2 |
5 files changed, 73 insertions, 9 deletions
@@ -1,3 +1,18 @@ +Fri Jun 30 19:50:25 2017 Eric Wong <e@80x24.org> + + * variable.c (autoload_reset): use idempotent list_del_init + + * variable.c (autoload_sleep): moved code from rb_autoload_load + + * variable.c (autoload_sleep_done): cleanup for use with rb_ensure + + * variable.c (rb_autoload_load): ensure list delete happens in case the + thread dies during sleep + + * test/ruby/bug-13526.rb: new script for separate execution + + * test/ruby/test_autoload.rb (test_bug_13526): new test [Bug #13526] + Fri Jun 30 19:46:46 2017 Nobuyoshi Nakada <nobu@ruby-lang.org> * sprintf.c (rb_str_format): while "% 2f" and "% 4f" result in " Inf" diff --git a/test/ruby/bug-13526.rb b/test/ruby/bug-13526.rb new file mode 100644 index 0000000000..f42e1913ce --- /dev/null +++ b/test/ruby/bug-13526.rb @@ -0,0 +1,20 @@ +# From https://bugs.ruby-lang.org/issues/13526#note-1 + +sleep if $load +$load = true + +n = 10 +threads = Array.new(n) do + Thread.new do + begin + autoload :Foo, "#{File.dirname($0)}/#{$0}" + Thread.pass + Foo + ensure + Thread.pass + end + end +end + +Thread.pass while threads.all?(&:stop?) +100.times { Thread.pass } diff --git a/test/ruby/test_autoload.rb b/test/ruby/test_autoload.rb index b793fd2a7f..aabcb4a400 100644 --- a/test/ruby/test_autoload.rb +++ b/test/ruby/test_autoload.rb @@ -235,6 +235,11 @@ p Foo::Bar end end + def test_bug_13526 + script = File.join(__dir__, 'bug-13526.rb') + assert_ruby_status([script], '', '[ruby-core:81016] [Bug #13526]') + end + def add_autoload(path) (@autoload_paths ||= []) << path ::Object.class_eval {autoload(:AutoloadTest, path)} diff --git a/variable.c b/variable.c index 2b8ee6672b..738494110c 100644 --- a/variable.c +++ b/variable.c @@ -2127,7 +2127,7 @@ autoload_reset(VALUE arg) VALUE th = cur->thread; cur->thread = Qfalse; - list_del(&cur->waitq.node); + list_del_init(&cur->waitq.node); /* idempotent */ /* * cur is stored on the stack of cur->waiting_th, @@ -2140,6 +2140,34 @@ autoload_reset(VALUE arg) return 0; /* ignored */ } +static VALUE +autoload_sleep(VALUE arg) +{ + struct autoload_state *state = (struct autoload_state *)arg; + + /* + * autoload_reset in other thread will resume us and remove us + * from the waitq list + */ + do { + rb_thread_sleep_deadly(); + } while (state->thread != Qfalse); + + return Qfalse; +} + +static VALUE +autoload_sleep_done(VALUE arg) +{ + struct autoload_state *state = (struct autoload_state *)arg; + + if (state->thread != Qfalse && rb_thread_to_be_killed(state->thread)) { + list_del_init(&state->waitq.node); /* idempotent */ + } + + return Qfalse; +} + VALUE rb_autoload_load(VALUE mod, ID id) { @@ -2177,13 +2205,9 @@ rb_autoload_load(VALUE mod, ID id) } else { list_add_tail(&ele->state->waitq.head, &state.waitq.node); - /* - * autoload_reset in other thread will resume us and remove us - * from the waitq list - */ - do { - rb_thread_sleep_deadly(); - } while (state.thread != Qfalse); + + rb_ensure(autoload_sleep, (VALUE)&state, + autoload_sleep_done, (VALUE)&state); } /* autoload_data_i can be deleted by another thread while require */ @@ -1,6 +1,6 @@ #define RUBY_VERSION "2.3.5" #define RUBY_RELEASE_DATE "2017-06-30" -#define RUBY_PATCHLEVEL 315 +#define RUBY_PATCHLEVEL 316 #define RUBY_RELEASE_YEAR 2017 #define RUBY_RELEASE_MONTH 6 |
