[ruby-cvs:71630] normal:r64538 (trunk): thread_pthread.c: main thread always gets hit by signals

normal at ruby-lang.org normal at ruby-lang.org
Sun Aug 26 06:59:31 JST 2018


normal	2018-08-26 06:59:30 +0900 (Sun, 26 Aug 2018)

  New Revision: 64538

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

  Log:
    thread_pthread.c: main thread always gets hit by signals
    
    We need to ensure Signal.trap handlers can function if the main
    thread is sleeping after a subthread has grabbed sigwait_fd,
    but later exited.
    
    Consider the following timeline:
    
    main_thread             sub-thread
    -----------------------------------------
    Signal.trap() { ... }
                            get sigwait_fd
                            ppoll on sigwait_fd
    native_cond_sleep
    (via pthread_cond_wait)
                            ppoll times-out
    put sigwait_fd
                            sub-thread exits
    
    only thread alive
    SIGNAL HITS
    
    The problem is pthread_cond_wait cannot return EINTR,
    so we can never run the Signal.trap handler.  So we
    will avoid using native_cond_sleep in the main thread
    and always use ppoll to sleep when in the main thread.
    This can guarantee the main thread remains aware of
    signals; even if it cannot safely read off sigwait_fd

  Modified files:
    trunk/test/ruby/test_signal.rb
    trunk/thread_pthread.c


More information about the ruby-cvs mailing list