[MacRuby] #883: Abort occurs when calls Thread#kill, Using 32bit arch.
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- {{{ #!ruby # spec/frozen/core/thread/alive_spec.rb # it "describes a running thread" do t = Thread.new { sleep 1 } t.kill }}} Result: {{{ $ DYLD_LIBRARY_PATH=. ./macruby -v -I./lib t.rb MacRuby 0.7 (ruby 1.9.2) [universal-darwin10.0, i386] terminate called after throwing an instance of 'RoxorThreadRaiseException*' zsh: abort DYLD_LIBRARY_PATH=. ./macruby -v -I./lib t.rb }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/883> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): It seem to do crash when rb_vm_thread_throw_kill() and rb_exit() are executed. {{{ (gdb) r Starting program: /Users/watson/src/MacRuby/macruby -v -I./lib t.rb warning: posix_spawn failed, trying execvp, error: 86 MacRuby 0.7 (ruby 1.9.2) [universal-darwin10.0, i386] Breakpoint 2, rb_exit (status=0) at process.c:2473 2473 ruby_finalize(); (gdb) c Continuing. [Switching to process 50554] Breakpoint 1, rb_vm_thread_throw_kill () at vm.cpp:4393 4393 throw new RoxorThreadRaiseException(); (gdb) bt #0 rb_vm_thread_throw_kill () at vm.cpp:4393 #1 0x00138d64 in rb_vm_thread_destructor (userdata=0x207a9d0) at vm.cpp:4399 #2 0x91895ddb in _pthread_exit () #3 0x9188df4a in _pthread_testcancel () #4 0x9188d8e7 in _pthread_cond_wait () #5 0x9188d875 in pthread_cond_timedwait$UNIX2003 () #6 0x00147c4f in rb_thread_wait_for (time={tv_sec = 1, tv_usec = 0}) at vm.cpp:4606 #7 0x0008d7ae in rb_f_sleep (recv=33676048, sel=0x15b6c80, argc=1, argv=0xb0184c04) at process.c:2930 #8 0x0012cd27 in ruby_dispatch [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:435 #9 0x0012cd27 in rb_vm_dispatch () at dispatcher.cpp:816 #10 0x01700505 in ?? () #11 0x017008e3 in ?? () #12 0x00130d58 in __rb_vm_bcall [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:98 #13 0x00130d58 in vm_block_eval [inlined] () at /Users/watson/src/MacRuby/dispatcher.cpp:1162 #14 0x00130d58 in rb_vm_block_eval (b=0x204f100, argc=0, argv=0x0) at dispatcher.cpp:1169 #15 0x001477ba in rb_vm_thread_run (thread=34056656) at vm.cpp:4423 #16 0x9188d81d in _pthread_start () #17 0x9188d6a2 in thread_start () Current language: auto; currently c++ (gdb) n terminate called after throwing an instance of 'RoxorThreadRaiseException*' Program received signal SIGABRT, Aborted. [Switching to process 50554] 0x91860142 in semaphore_wait_signal_trap () }}} {{{ (gdb) r Starting program: /Users/watson/src/MacRuby/macruby -v -I./lib t.rb warning: posix_spawn failed, trying execvp, error: 86 MacRuby 0.7 (ruby 1.9.2) [universal-darwin10.0, i386] [Switching to process 50611] Breakpoint 2, rb_vm_thread_throw_kill () at vm.cpp:4393 4393 throw new RoxorThreadRaiseException(); (gdb) c Continuing. Current language: auto; currently c++ [Switching to process 50611] Breakpoint 1, rb_exit (status=0) at process.c:2473 2473 ruby_finalize(); (gdb) bt #0 rb_exit (status=0) at process.c:2473 #1 0x00001b52 in main (argc=4, argv=0x15060f0, envp=0xbfffe980) at main.cpp:40 Current language: auto; currently c (gdb) c Continuing. terminate called after throwing an instance of 'RoxorThreadRaiseException*' Program received signal SIGABRT, Aborted. 0x91865aa4 in pthread_mutex_lock () }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:1> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): MacRuby throws a C++'s exception when rb_vm_thread_destructor() is executed after calls pthread_cancel(). [[BR]] When the thread is really dead, can't catch the exception. [[BR]] The thread is dead when executes a cancellation point (nanosleep, pthread_cond_wait, pthread_testcancel, etc). abort did not occur by the following changes, but unfortunately the spec does not do pass X( {{{ #!diff diff --git a/vm.cpp b/vm.cpp index 71d3f8a..2a6bf4d 100644 --- a/vm.cpp +++ b/vm.cpp @@ -4544,6 +4544,7 @@ rb_vm_thread_pre_init(rb_vm_thread_t *t, rb_vm_block_t *body, int argc, t->in_cond_wait = false; t->abort_on_exception = false; t->joined_on_exception = false; + t->canceled = false; t->group = Qnil; // will be set right after t->mutexes = Qnil; @@ -4582,8 +4583,10 @@ rb_thread_sleep_forever() } pre_wait(t); - const int code = pthread_cond_wait(&t->sleep_cond, &t->sleep_mutex); - assert(code == 0 || code == ETIMEDOUT); + if (t->canceled == false) { + const int code = pthread_cond_wait(&t->sleep_cond, &t->sleep_mutex); + assert(code == 0 || code == ETIMEDOUT); + } post_wait(t); } @@ -4605,9 +4608,11 @@ rb_thread_wait_for(struct timeval time) rb_vm_thread_t *t = GET_THREAD(); pre_wait(t); - const int code = pthread_cond_timedwait(&t->sleep_cond, &t->sleep_mutex, - &ts); - assert(code == 0 || code == ETIMEDOUT); + if (t->canceled == false) { + const int code = pthread_cond_timedwait(&t->sleep_cond, &t->sleep_mutex, + &ts); + assert(code == 0 || code == ETIMEDOUT); + } post_wait(t); } @@ -4646,6 +4651,7 @@ rb_vm_thread_cancel(rb_vm_thread_t *t) pthread_assert(pthread_cond_signal(&t->sleep_cond)); } else { + t->canceled = true; pthread_assert(pthread_cancel(t->thread)); } pthread_assert(pthread_mutex_unlock(&t->sleep_mutex)); diff --git a/vm.h b/vm.h index 5df84ee..038c7a8 100644 --- a/vm.h +++ b/vm.h @@ -151,6 +151,7 @@ typedef struct rb_vm_thread { bool in_cond_wait; bool abort_on_exception; // per-local state, global one is in RoxorCore bool joined_on_exception; + bool canceled; VALUE locals; // a Hash object or Qnil VALUE exception; // killed-by exception or Qnil VALUE group; // always a ThreadGroup object }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:2> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): I think that #884 #883 #874 are same problem. -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:3> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by lsansonetti@…): But #884 and #883 are only for 32-bit, and #874 crashes on both 32/64-bit. Is that right? It does not seem to be critical for the 0.7 release, but the 32-bit-only problems seem serious. -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:4> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…):
But #884 and #883 are only for 32-bit, and #874 crashes on both 32/64-bit. Is that right? Certainty, #884 and #883 does not crash on 64bit.
MacRuby works on 32bit and 64bit in the same way, I wonder that only 64bit does not crash. -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:5> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby 1.0 Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Changes (by mattaimonetti@…): * milestone: => MacRuby 1.0 -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:6> MacRuby <http://macruby.org/>
#883: Abort occurs when calls Thread#kill, Using 32bit arch. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: MacRuby Later Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * milestone: MacRuby 1.0 => MacRuby Later Comment: 32-bit only problems are for Later. -- Ticket URL: <http://www.macruby.org/trac/ticket/883#comment:7> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby