[ruby-cvs:58724] normal:r51576 (trunk): improve handling of timer thread shutdown

normal at ruby-lang.org normal at ruby-lang.org
Fri Aug 14 18:44:11 JST 2015

normal	2015-08-14 18:44:10 +0900 (Fri, 14 Aug 2015)

  New Revision: 51576


    improve handling of timer thread shutdown
    Shutting down the timer thread now always closes pipes to free FDs.
    In fact, we close the write ends of the pipes is done in the main
    RubyVM to signal the timer thread shutdown.
    To effectively close pipes, we implement userspace locks via
    atomics to force the pipe closing thread to wait on any signal
    handlers which may be waking up.
    While we're at it, improve robustness during resource exhaustion and
    allow it to limp along non-fatally if restarting a timer thread
    This reverts r51268
    Note: this change is tested with VM_CHECK_MODE 1 in vm_core.h
    * process.c (close_unless_reserved): add extra check
      (dup2_with_divert): remove
      (redirect_dup2): use dup2 without divert
      (before_exec_non_async_signal_safe): adjust call + comment
      (rb_f_exec): stop timer thread for all OSes
      (rb_exec_without_timer_thread): remove
    * eval.c (ruby_cleanup): adjust call
    * thread.c (rb_thread_stop_timer_thread): always close pipes
    * thread_pthread.c (struct timer_thread_pipe): add writing field,
        mark owner_process volatile for signal handlers
      (rb_thread_wakeup_timer_thread_fd): check valid FD
      (rb_thread_wakeup_timer_thread): set writing flag to prevent close
      (rb_thread_wakeup_timer_thread_low): ditto
      (CLOSE_INVALIDATE): new macro
      (close_invalidate): new function
      (close_communication_pipe): removed
      (setup_communication_pipe_internal): make errors non-fatal
      (setup_communication_pipe): ditto
      (thread_timer): close reading ends inside timer thread
      (rb_thread_create_timer_thread): make errors non-fatal
      (native_stop_timer_thread): close write ends only, always,
       wait for signal handlers to finish
      (rb_divert_reserved_fd): remove
    * thread_win32.c (native_stop_timer_thread): adjust (untested)
      (rb_divert_reserved_fd): remove
    * vm_core.h: adjust prototype

  Modified files:

More information about the ruby-cvs mailing list