[前][次][番号順一覧][スレッド一覧]

ruby-changes:45965

From: nagachika <ko1@a...>
Date: Mon, 20 Mar 2017 21:26:19 +0900 (JST)
Subject: [ruby-changes:45965] nagachika:r58036 (ruby_2_3): merge revision(s) 57477, 57478, 57479: [Backport #12405]

nagachika	2017-03-20 21:26:14 +0900 (Mon, 20 Mar 2017)

  New Revision: 58036

  https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=58036

  Log:
    merge revision(s) 57477,57478,57479: [Backport #12405]
    
    use TRUE/FALSE.
    
    define rb_thread_sleep_deadly_allow_spurious_wakeup().
    
    * thread.c, thread_sync.c: define new function
      rb_thread_sleep_deadly_allow_spurious_wakeup() and use it instead of
      using sleep_forever() directly.
    
    allow Queue operation in trap.
    
    * thread_sync.c: allow spurious wakeup to check Queue status just after trap.
      [Bug #12405]
    
    * test/thread/test_queue.rb: add a test for it.

  Modified directories:
    branches/ruby_2_3/
  Modified files:
    branches/ruby_2_3/test/thread/test_queue.rb
    branches/ruby_2_3/thread.c
    branches/ruby_2_3/thread_sync.c
    branches/ruby_2_3/version.h
Index: ruby_2_3/thread_sync.c
===================================================================
--- ruby_2_3/thread_sync.c	(revision 58035)
+++ ruby_2_3/thread_sync.c	(revision 58036)
@@ -416,7 +416,7 @@ rb_mutex_abandon_all(rb_mutex_t *mutexes https://github.com/ruby/ruby/blob/trunk/ruby_2_3/thread_sync.c#L416
 static VALUE
 rb_mutex_sleep_forever(VALUE time)
 {
-    sleep_forever(GET_THREAD(), 1, 0); /* permit spurious check */
+    rb_thread_sleep_deadly_allow_spurious_wakeup();
     return Qnil;
 }
 
@@ -763,7 +763,7 @@ queue_delete_from_waiting(struct waiting https://github.com/ruby/ruby/blob/trunk/ruby_2_3/thread_sync.c#L763
 static VALUE
 queue_sleep(VALUE arg)
 {
-    rb_thread_sleep_deadly();
+    rb_thread_sleep_deadly_allow_spurious_wakeup();
     return Qnil;
 }
 
Index: ruby_2_3/version.h
===================================================================
--- ruby_2_3/version.h	(revision 58035)
+++ ruby_2_3/version.h	(revision 58036)
@@ -1,6 +1,6 @@ https://github.com/ruby/ruby/blob/trunk/ruby_2_3/version.h#L1
 #define RUBY_VERSION "2.3.3"
 #define RUBY_RELEASE_DATE "2017-03-20"
-#define RUBY_PATCHLEVEL 254
+#define RUBY_PATCHLEVEL 255
 
 #define RUBY_RELEASE_YEAR 2017
 #define RUBY_RELEASE_MONTH 3
Index: ruby_2_3/test/thread/test_queue.rb
===================================================================
--- ruby_2_3/test/thread/test_queue.rb	(revision 58035)
+++ ruby_2_3/test/thread/test_queue.rb	(revision 58036)
@@ -541,4 +541,21 @@ class TestQueue < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/ruby_2_3/test/thread/test_queue.rb#L541
     # don't leak this thread
     assert_nothing_raised{counter.join}
   end
+
+  def test_queue_with_trap
+    assert_in_out_err([], <<-INPUT, %w(USR2 USR2 exit), [])
+      q = Queue.new
+      trap(:USR2){
+        q.push 'USR2'
+      }
+      Thread.new{
+        loop{
+          Process.kill :USR2, $$
+        }
+      }
+      puts q.pop
+      puts q.pop
+      puts 'exit'
+    INPUT
+  end
 end
Index: ruby_2_3/thread.c
===================================================================
--- ruby_2_3/thread.c	(revision 58035)
+++ ruby_2_3/thread.c	(revision 58036)
@@ -85,6 +85,7 @@ static ID id_locals; https://github.com/ruby/ruby/blob/trunk/ruby_2_3/thread.c#L85
 static void sleep_timeval(rb_thread_t *th, struct timeval time, int spurious_check);
 static void sleep_wait_for_interrupt(rb_thread_t *th, double sleepsec, int spurious_check);
 static void sleep_forever(rb_thread_t *th, int nodeadlock, int spurious_check);
+static void rb_thread_sleep_deadly_allow_spurious_wakeup(void);
 static double timeofday(void);
 static int rb_threadptr_dead(rb_thread_t *th);
 static void rb_check_deadlock(rb_vm_t *vm);
@@ -840,7 +841,7 @@ thread_join_sleep(VALUE arg) https://github.com/ruby/ruby/blob/trunk/ruby_2_3/thread.c#L841
 
     while (target_th->status != THREAD_KILLED) {
 	if (forever) {
-	    sleep_forever(th, 1, 0);
+	    sleep_forever(th, TRUE, FALSE);
 	}
 	else {
 	    double now = timeofday();
@@ -1131,14 +1132,21 @@ void https://github.com/ruby/ruby/blob/trunk/ruby_2_3/thread.c#L1132
 rb_thread_sleep_forever(void)
 {
     thread_debug("rb_thread_sleep_forever\n");
-    sleep_forever(GET_THREAD(), 0, 1);
+    sleep_forever(GET_THREAD(), FALSE, TRUE);
 }
 
 void
 rb_thread_sleep_deadly(void)
 {
     thread_debug("rb_thread_sleep_deadly\n");
-    sleep_forever(GET_THREAD(), 1, 1);
+    sleep_forever(GET_THREAD(), TRUE, TRUE);
+}
+
+static void
+rb_thread_sleep_deadly_allow_spurious_wakeup(void)
+{
+    thread_debug("rb_thread_sleep_deadly_allow_spurious_wakeup\n");
+    sleep_forever(GET_THREAD(), TRUE, FALSE);
 }
 
 static double

Property changes on: ruby_2_3
___________________________________________________________________
Modified: svn:mergeinfo
   Merged /trunk:r57477-57479


--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]