ruby-changes:51582
From: normal <ko1@a...>
Date: Sat, 30 Jun 2018 07:13:07 +0900 (JST)
Subject: [ruby-changes:51582] normal:r63793 (trunk): signal.c: use ATOMIC_EXCHANGE for sigchld_hit
normal 2018-06-30 07:13:02 +0900 (Sat, 30 Jun 2018) New Revision: 63793 https://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=revision&revision=63793 Log: signal.c: use ATOMIC_EXCHANGE for sigchld_hit sig_atomic_t may not be sufficient for multi-threaded applications if the sighandler runs on a different CPU than timer thread. Modified files: trunk/signal.c Index: signal.c =================================================================== --- signal.c (revision 63792) +++ signal.c (revision 63793) @@ -692,7 +692,7 @@ signal_enque(int sig) https://github.com/ruby/ruby/blob/trunk/signal.c#L692 ATOMIC_INC(signal_buff.size); } -static sig_atomic_t sigchld_hit; +static rb_atomic_t sigchld_hit; /* Prevent compiler from reordering access */ #define ACCESS_ONCE(type,x) (*((volatile type *)&(x))) @@ -705,7 +705,7 @@ sighandler(int sig) https://github.com/ruby/ruby/blob/trunk/signal.c#L705 /* the VM always needs to handle SIGCHLD for rb_waitpid */ if (sig == RUBY_SIGCHLD) { rb_vm_t *vm = GET_VM(); - sigchld_hit = 1; + ATOMIC_EXCHANGE(sigchld_hit, 1); /* avoid spurious wakeup in main thread iff nobody uses trap(:CHLD) */ if (vm && ACCESS_ONCE(VALUE, vm->trap_list.cmd[sig])) { @@ -1066,8 +1066,7 @@ void ruby_waitpid_all(rb_vm_t *); /* pro https://github.com/ruby/ruby/blob/trunk/signal.c#L1066 void ruby_sigchld_handler(rb_vm_t *vm) { - if (sigchld_hit) { - sigchld_hit = 0; + if (ATOMIC_EXCHANGE(sigchld_hit, 0)) { ruby_waitpid_all(vm); } } -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/