From 33a17d48397518c2110be41ad8793705a701a7fe Mon Sep 17 00:00:00 2001 From: ngoto Date: Thu, 25 Jun 2015 12:42:07 +0000 Subject: * test/-ext-/popen_deadlock/test_popen_deadlock.rb: test [Bug #11265] * ext/-test-/popen_deadlock/infinite_loop_dlsym.c: new ext to call dlsym(3) infinitely without GVL, used in the above test. * ext/-test-/popen_deadlock/extconf.rb: extconf.rb for the above ext. Currently, only enabled on Solaris (main target) and Linux (as a reference platform and for debugging the ext). git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51030 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- ext/-test-/popen_deadlock/extconf.rb | 4 ++ ext/-test-/popen_deadlock/infinite_loop_dlsym.c | 50 +++++++++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 ext/-test-/popen_deadlock/extconf.rb create mode 100644 ext/-test-/popen_deadlock/infinite_loop_dlsym.c (limited to 'ext/-test-') diff --git a/ext/-test-/popen_deadlock/extconf.rb b/ext/-test-/popen_deadlock/extconf.rb new file mode 100644 index 0000000000..f993ff7f9a --- /dev/null +++ b/ext/-test-/popen_deadlock/extconf.rb @@ -0,0 +1,4 @@ +case RUBY_PLATFORM +when /solaris/i, /linux/i + create_makefile("-test-/popen_deadlock/infinite_loop_dlsym") +end diff --git a/ext/-test-/popen_deadlock/infinite_loop_dlsym.c b/ext/-test-/popen_deadlock/infinite_loop_dlsym.c new file mode 100644 index 0000000000..1d95a7cc9a --- /dev/null +++ b/ext/-test-/popen_deadlock/infinite_loop_dlsym.c @@ -0,0 +1,50 @@ +#include "ruby/ruby.h" +#include "ruby/thread.h" +#include + +struct data_for_loop_dlsym { + const char *name; + volatile int stop; +}; + +static void* +native_loop_dlsym(void *data) +{ + struct data_for_loop_dlsym *s = data; + + while (!(s->stop)) { + dlsym(RTLD_DEFAULT, s->name); + } + + return NULL; +} + +static void +ubf_for_loop_dlsym(void *data) +{ + struct data_for_loop_dlsym *s = data; + + s->stop = 1; + + return; +} + +static VALUE +loop_dlsym(VALUE self, VALUE name) +{ + struct data_for_loop_dlsym d; + + d.stop = 0; + d.name = StringValuePtr(name); + + rb_thread_call_without_gvl(native_loop_dlsym, &d, + ubf_for_loop_dlsym, &d); + + return self; +} + +void +Init_infinite_loop_dlsym(void) +{ + rb_define_method(rb_cThread, "__infinite_loop_dlsym__", loop_dlsym, 1); +} -- cgit v1.2.3