ruby-changes:54622
From: nagachika <ko1@a...>
Date: Wed, 16 Jan 2019 21:05:03 +0900 (JST)
Subject: [ruby-changes:54622] nagachika:r66837 (ruby_2_5): merge revision(s) 64476: [Backport #15084]
nagachika 2019-01-16 21:04:57 +0900 (Wed, 16 Jan 2019) New Revision: 66837 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=66837 Log: merge revision(s) 64476: [Backport #15084] thread_sync.c (rb_mutex_sleep): disable interrupt checking in ensure This is needed to reliably fix ConditionVariable#wait on Thread#kill [Bug #14999] because there is still a chance an interrupt could fire and prevent lock acquisition after an ensure statement. Arguably, rb_mutex_lock itself should be uninterruptible, but that already prevents bootstraptest/test_thread.rb from completing and probably breaks existing use cases. For reference, POSIX expressly forbids EINTR from pthread_mutex_lock. [ruby-core:88556] [Bug #14999] Modified directories: branches/ruby_2_5/ Modified files: branches/ruby_2_5/thread_sync.c branches/ruby_2_5/version.h Index: ruby_2_5/thread_sync.c =================================================================== --- ruby_2_5/thread_sync.c (revision 66836) +++ ruby_2_5/thread_sync.c (revision 66837) @@ -221,15 +221,8 @@ rb_mutex_trylock(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/thread_sync.c#L221 */ static const rb_thread_t *patrol_thread = NULL; -/* - * call-seq: - * mutex.lock -> self - * - * Attempts to grab the lock and waits if it isn't available. - * Raises +ThreadError+ if +mutex+ was locked by the current thread. - */ -VALUE -rb_mutex_lock(VALUE self) +static VALUE +do_mutex_lock(VALUE self, int interruptible_p) { rb_thread_t *th = GET_THREAD(); rb_mutex_t *mutex; @@ -290,16 +283,37 @@ rb_mutex_lock(VALUE self) https://github.com/ruby/ruby/blob/trunk/ruby_2_5/thread_sync.c#L283 th->vm->sleeper--; if (mutex->th == th) mutex_locked(th, self); - RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */ - if (!mutex->th) { - mutex->th = th; - mutex_locked(th, self); - } + if (interruptible_p) { + RUBY_VM_CHECK_INTS_BLOCKING(th->ec); /* may release mutex */ + if (!mutex->th) { + mutex->th = th; + mutex_locked(th, self); + } + } } } return self; } +static VALUE +mutex_lock_uninterruptible(VALUE self) +{ + return do_mutex_lock(self, 0); +} + +/* + * call-seq: + * mutex.lock -> self + * + * Attempts to grab the lock and waits if it isn't available. + * Raises +ThreadError+ if +mutex+ was locked by the current thread. + */ +VALUE +rb_mutex_lock(VALUE self) +{ + return do_mutex_lock(self, 1); +} + /* * call-seq: * mutex.owned? -> true or false @@ -462,11 +476,12 @@ rb_mutex_sleep(VALUE self, VALUE timeout https://github.com/ruby/ruby/blob/trunk/ruby_2_5/thread_sync.c#L476 rb_mutex_unlock(self); beg = time(0); if (NIL_P(timeout)) { - rb_ensure(rb_mutex_sleep_forever, Qnil, rb_mutex_lock, self); + rb_ensure(rb_mutex_sleep_forever, Qnil, mutex_lock_uninterruptible, self); } else { - rb_ensure(rb_mutex_wait_for, (VALUE)&t, rb_mutex_lock, self); + rb_ensure(rb_mutex_wait_for, (VALUE)&t, mutex_lock_uninterruptible, self); } + RUBY_VM_CHECK_INTS_BLOCKING(GET_EC()); end = time(0) - beg; return INT2FIX(end); } Index: ruby_2_5/version.h =================================================================== --- ruby_2_5/version.h (revision 66836) +++ ruby_2_5/version.h (revision 66837) @@ -1,10 +1,10 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_5/version.h#L1 #define RUBY_VERSION "2.5.4" -#define RUBY_RELEASE_DATE "2019-01-14" -#define RUBY_PATCHLEVEL 129 +#define RUBY_RELEASE_DATE "2019-01-16" +#define RUBY_PATCHLEVEL 130 #define RUBY_RELEASE_YEAR 2019 #define RUBY_RELEASE_MONTH 1 -#define RUBY_RELEASE_DAY 14 +#define RUBY_RELEASE_DAY 16 #include "ruby/version.h" Index: ruby_2_5 =================================================================== --- ruby_2_5 (revision 66836) +++ ruby_2_5 (revision 66837) Property changes on: ruby_2_5 ___________________________________________________________________ Modified: svn:mergeinfo ## -0,0 +0,1 ## Merged /trunk:r64476 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/