ruby/test
normal 708bfd2115 thread_pthread: remove timer-thread by restructuring GVL
To reduce resource use and reduce CI failure; remove
timer-thread.  Single-threaded Ruby processes (including forked
children) will never see extra thread overhead.  This prevents
glibc and jemalloc from going into multi-threaded mode and
initializing locks or causing fragmentation via arena explosion.

The GVL is implements its own wait-queue as a ccan/list to
permit controlling wakeup order.  Timeslice under contention is
handled by a designated timer thread (similar to choosing a
"patrol_thread" for current deadlock checking).

There is only one self-pipe, now, as wakeups for timeslice are
done independently using condition variables.  This reduces FD
pressure slightly.

Signal handling is handled directly by a Ruby Thread (instead
of timer-thread) by exposing signal self-pipe to callers of
rb_thread_fd_select, native_sleep, rb_wait_for_single_fd, etc...
Acquiring, using, and releasing the self-pipe is exposed via 4
new internal functions:

1) rb_sigwait_fd_get - exclusively acquire timer_thread_pipe.normal[0]

2) rb_sigwait_fd_sleep - sleep and wait for signal (and no other FDs)

3) rb_sigwait_fd_put - release acquired result from rb_sigwait_fd_get

4) rb_sigwait_fd_migrate - migrate signal handling to another thread
                           after calling rb_sigwait_fd_put.

rb_sigwait_fd_migrate is necessary for waitpid callers because
only one thread can wait on self-pipe at a time, otherwise a
deadlock will occur if threads fight over the self-pipe.

TRAP_INTERRUPT_MASK is now set for the main thread directly in
signal handler via rb_thread_wakeup_timer_thread.

Originally, I wanted to use POSIX timers
(timer_create/timer_settime) for this.  Unfortunately, this
proved unfeasible as Mutex#sleep resumes on spurious wakeups and
test/thread/test_cv.rb::test_condvar_timed_wait failed.  Using
pthread_sigmask to mask out SIGVTALRM fixed that test,  but
test/fiddle/test_function.rb::test_nogvl_poll proved there'd be
some unavoidable (and frequent) incompatibilities from that
approach.

Finally, this allows us to drop thread_destruct_lock and
interrupt current ec directly.

We don't need to rely on vm->thread_destruct_lock or a coherent
vm->running_thread on any platform.  Separate timer-thread for
time slice and signal handling is relegated to thread_win32.c,
now.

[ruby-core:88088] [Misc #14937]

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@64107 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2018-07-29 20:47:33 +00:00
..
-ext- test/-ext-/gvl/test_last_thread.rb: skip under MJIT 2018-07-20 22:30:39 +00:00
base64 lib/base64.rb: Specify frozen_string_literal: true. 2017-02-10 00:58:45 +00:00
benchmark lib/benchmark.rb: Specify frozen_string_literal: true. 2017-01-03 02:00:01 +00:00
bigdecimal `$SAFE` as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
cgi Revert "ext/cgi/escape: preserve String subclass in result" 2018-05-03 01:24:09 +00:00
coverage test/coverage/test_coverage.rb: make the expected value the same as 2.4 2017-12-20 04:45:05 +00:00
csv Merge csv-1.0.2 from upstream. 2018-05-09 04:39:16 +00:00
date test/date/test_date_base.rb: removed 2018-04-17 08:18:56 +00:00
dbm skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
digest Fix tests which fail with extra stderr output when a Thread dies 2017-12-12 18:44:21 +00:00
drb drb: use \A and \z 2017-12-30 12:10:43 +00:00
dtrace test/dtrace/helper.rb: support systemtap in dtrace tests 2018-06-05 21:19:50 +00:00
erb Rename test classes to allow stable test count when running test-all -j 2018-03-13 06:29:02 +00:00
etc test_etc.rb: fix test_getgrnam for duplicated group names 2017-09-29 17:19:37 +00:00
excludes TestException.rb: suppress warning 2016-04-11 08:27:19 +00:00
fiddle test_function.rb: fix messages 2018-07-28 13:06:43 +00:00
fileutils Retry to merge fileutils-1.1.0. 2018-05-15 05:53:18 +00:00
gdbm Use assert(false) for the path that is expected unreachable 2018-04-17 08:18:57 +00:00
io test/io/console/test_io_console.rb: fix for systems where PTY is not defined 2018-06-06 01:12:23 +00:00
irb irb.rb: update `_` 2018-05-12 09:13:45 +00:00
json require 'bigdecimal' 2017-06-16 04:04:53 +00:00
lib test_jit.rb: test unload_units 2018-07-27 05:52:01 +00:00
logger Remove unused variables 2018-03-17 06:41:35 +00:00
matrix lib/matrix: Add hadamard_product/entrywise_product. 2017-11-20 02:18:43 +00:00
minitest use https:// instead of http:// 2018-07-28 10:00:27 +00:00
misc test_ruby_mode.rb: fix for Emacs 25.1 2016-09-24 01:19:43 +00:00
mkmf a C source code must end with EOL 2018-02-17 10:04:22 +00:00
monitor Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
net increase body size 2018-06-25 12:11:31 +00:00
nkf Fix test code of kconv 2017-09-15 16:56:16 +00:00
objspace io.c: encoding of ARGF.inplace_mode 2017-10-10 12:30:42 +00:00
open-uri open-uri defines URI.open defined as an alias. 2017-12-21 14:15:04 +00:00
openssl openssl: merge changes in v2.1.1 2018-05-12 07:33:53 +00:00
optparse optparse: Suppress warnings 2018-05-06 09:53:33 +00:00
ostruct lib/ostruct.rb: Use `FrozenError` instead of `RuntimeError`. 2018-02-06 23:52:30 +00:00
pathname skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
psych Merge Pysch 3.0.3.pre1. 2018-04-28 01:47:58 +00:00
rdoc Merge rdoc-6.0.4 from upstream. 2018-05-08 02:07:53 +00:00
readline `$SAFE` as a process global state. [Feature #14250] 2017-12-28 20:09:24 +00:00
resolv use the reference as failure messages 2018-03-06 05:59:29 +00:00
rexml rexml: disable XPath 1.0 compatible "#{ELEMENT_NAME}" processing by default 2018-04-28 01:36:18 +00:00
rinda Fix test-all tests to avoid creating report_on_exception warnings 2017-12-12 18:44:49 +00:00
ripper test/ripper/test_lexer.rb: add test for r62743 2018-03-13 13:03:12 +00:00
rss rss: Add option Hash support to RSS::Parser.parse 2018-05-12 09:06:00 +00:00
ruby thread_pthread: remove timer-thread by restructuring GVL 2018-07-29 20:47:33 +00:00
rubygems Skip more rubygems tests when openssl is missing 2018-07-04 12:45:46 +00:00
scanf Fix bug about String#scanf("%a") 2017-10-21 12:34:13 +00:00
sdbm skip some tests so that no failure occurs in root privilege 2018-01-10 10:39:09 +00:00
shell Promote Shell library to default gems. 2018-07-20 02:24:59 +00:00
socket test/socket/test_socket.rb (test_timestamp): retry send 2018-07-07 05:34:03 +00:00
stringio Add FrozenError as a subclass of RuntimeError 2017-12-12 00:46:34 +00:00
strscan strscan.c: add MatchData-like methods 2017-11-29 07:57:48 +00:00
syslog
testunit Use `&.` instead of modifier if 2018-06-10 03:10:13 +00:00
thread test/thread/test_cv.rb: test CV usability inside forked child 2018-04-30 23:53:55 +00:00
uri http_proxy setting should respect both parent domain and subdomain 2018-05-17 07:40:01 +00:00
webrick Add missing escape 2018-07-26 12:47:01 +00:00
win32ole Rename test classes to allow stable test count when running test-all -j 2018-03-13 06:29:02 +00:00
yaml lib/pstore.rb: Specify frozen_string_literal: true. 2017-01-17 12:47:38 +00:00
zlib test/zlib/test_zlib.rb (test_path): enable the accidentally-disabled assertion 2018-04-17 06:38:08 +00:00
colors
runner.rb the working directory may not be srcdir 2017-09-07 17:45:34 +00:00
test_abbrev.rb lib/abbrev.rb: Specify frozen_string_literal: true. 2017-02-09 16:12:00 +00:00
test_cmath.rb lib/cmath.rb: Specify frozen_string_literal: true. 2017-01-04 05:47:52 +00:00
test_delegate.rb Add FrozenError as a subclass of RuntimeError 2017-12-12 00:46:34 +00:00
test_extlibs.rb Revert "test/test_extilibs.rb: do not check the existence of fiddle" 2017-05-16 23:59:01 +00:00
test_find.rb Fix indent and use as skipped message instead of comment 2018-01-11 13:56:04 +00:00
test_forwardable.rb Add test for Forwardable#def_delegator with r55366. 2018-02-01 09:07:16 +00:00
test_ipaddr.rb Import ipaddr 1.2.0 2017-10-21 13:34:19 +00:00
test_mutex_m.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
test_observer.rb lib/observer.rb: Specify frozen_string_literal: true. 2017-01-13 12:08:29 +00:00
test_open3.rb Remove needless closed? 2018-06-17 15:42:35 +00:00
test_pp.rb
test_prettyprint.rb
test_prime.rb test/test_prime.rb: add testcases of prime library 2018-06-24 09:31:06 +00:00
test_pstore.rb lib/pstore.rb: Specify frozen_string_literal: true. 2017-01-17 12:47:38 +00:00
test_pty.rb Remove needless lines 2018-06-12 14:36:32 +00:00
test_rbconfig.rb
test_securerandom.rb Use `\A` and `\z` instead of `^` and `$` 2017-10-22 09:16:54 +00:00
test_set.rb Add a new #filter alias for #select 2018-02-25 13:52:07 +00:00
test_shellwords.rb Fix the handling of the backslash in double quotes 2016-11-05 04:58:48 +00:00
test_singleton.rb
test_syslog.rb
test_tempfile.rb Failed to unlink before close on mswin 2018-07-11 13:00:56 +00:00
test_time.rb time.rb: yday support 2018-07-24 07:47:01 +00:00
test_timeout.rb Remove unnecessary `require 'thread'` 2017-10-08 07:00:01 +00:00
test_tmpdir.rb test/test_{tempfile,tmpdir}: get rid of leftover files 2018-07-11 08:33:37 +00:00
test_tracer.rb
test_tsort.rb
test_unicode_normalize.rb fix range check for Hangul jamo trailers in Unicode normalization 2018-07-28 09:44:33 +00:00
test_weakref.rb lib/weakref.rb: Specify frozen_string_literal: true. 2017-01-26 15:14:00 +00:00
test_win32api.rb