From 23444302d9200bcc41ce279a529f73cad63c3f05 Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 4 Jan 2019 13:14:11 +0000 Subject: introduce rb_nogvl C-API to mark ubf as async-signal-safe zlib and bignum both contain unblocking functions which are async-signal-safe and do not require spawning additional threads. We can execute those functions directly in signal handlers without incurring overhead of extra threads, so provide C-API users the ability to deal with that. Other C-API users may have similar need. This flexible API can supercede existing uses of rb_thread_call_without_gvl and rb_thread_call_without_gvl2 by introducing a flags argument to control behavior. Note: this API is NOT finalized. It needs approval from other committers. I prefer shorter name than previous rb_thread_call_without_gvl* functions because my eyes requires big fonts. [Bug #15499] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@66712 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/-ext-/gvl/test_ubf_async_safe.rb | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) create mode 100644 test/-ext-/gvl/test_ubf_async_safe.rb (limited to 'test/-ext-') diff --git a/test/-ext-/gvl/test_ubf_async_safe.rb b/test/-ext-/gvl/test_ubf_async_safe.rb new file mode 100644 index 0000000000..85c4a7d38e --- /dev/null +++ b/test/-ext-/gvl/test_ubf_async_safe.rb @@ -0,0 +1,20 @@ +# frozen_string_literal: true +class TestUbfAsyncSafe < Test::Unit::TestCase + def test_ubf_async_safe + skip 'need fork for single-threaded test' unless Process.respond_to?(:fork) + IO.pipe do |r, w| + pid = fork do + require '-test-/gvl/call_without_gvl' + r.close + trap(:INT) { exit!(0) } + Thread.current.__ubf_async_safe__(w.fileno) + exit!(1) + end + w.close + assert IO.select([r], nil, nil, 30), 'child did not become ready' + Process.kill(:INT, pid) + _, st = Process.waitpid2(pid) + assert_predicate st, :success?, ':INT signal triggered exit' + end + end +end -- cgit v1.2.3