diff options
Diffstat (limited to 'test/ruby')
| -rw-r--r-- | test/ruby/test_thread.rb | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 703373b11e..bcd6590903 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -3,6 +3,7 @@ require 'test/unit' require "rbconfig/sizeof" require "timeout" +require "fiddle" class TestThread < Test::Unit::TestCase class Thread < ::Thread @@ -1443,6 +1444,35 @@ q.pop assert_nil th1.native_thread_id end + def test_thread_native_thread_id_across_fork_on_linux + rtld_default = Fiddle.dlopen(nil) + omit "this test is only for Linux" unless rtld_default.sym_defined?('gettid') + + gettid = Fiddle::Function.new(rtld_default['gettid'], [], Fiddle::TYPE_INT) + + parent_thread_id = Thread.main.native_thread_id + real_parent_thread_id = gettid.call + + assert_equal real_parent_thread_id, parent_thread_id + + child_lines = nil + IO.popen('-') do |pipe| + if pipe + # parent + child_lines = pipe.read.lines + else + # child + puts Thread.main.native_thread_id + puts gettid.call + end + end + child_thread_id = child_lines[0].chomp.to_i + real_child_thread_id = child_lines[1].chomp.to_i + + assert_equal real_child_thread_id, child_thread_id + refute_equal parent_thread_id, child_thread_id + end + def test_thread_interrupt_for_killed_thread opts = { timeout: 5, timeout_error: nil } |
