[MacRuby] #790: Exception is not generated when calls Thread.stop with only one thread.
#790: Exception is not generated when calls Thread.stop with only one thread. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Result of Ruby 1.9.1: {{{ $ irb irb(main):001:0> Thread.stop ThreadError: stopping only thread note: use sleep to stop forever from (irb):1:in `stop' from (irb):1 from /opt/local/bin/irb:12:in `<main>' }}} Result of MacRuby Trunk: {{{ $ macirb irb(main):001:0> Thread.stop ^C }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/790> MacRuby <http://macruby.org/>
#790: Exception is not generated when calls Thread.stop with only one thread. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: new Priority: blocker | Milestone: Component: MacRuby | Keywords: ----------------------------------+----------------------------------------- Comment(by watson1978@…): With the following patch, it would be fixed. :D {{{ #!diff diff --git a/thread.c b/thread.c index fe380ba..8a46dea 100644 --- a/thread.c +++ b/thread.c @@ -788,8 +788,8 @@ rb_thread_key_p(VALUE self, SEL sel, VALUE key) int rb_thread_alone() { - // TODO - return 0; + int num = RARRAY_LEN(rb_vm_threads()); + return num == 1; } /* diff --git a/vm.cpp b/vm.cpp index 1f6dc86..f5dbb54 100644 --- a/vm.cpp +++ b/vm.cpp @@ -4525,6 +4525,9 @@ rb_thread_sleep_forever() { rb_vm_thread_t *t = GET_THREAD(); + if(rb_thread_alone()) { + rb_raise(rb_eThreadError, "stopping only thread\n\tnote: use sleep to stop forever"); + } pre_wait(t); const int code = pthread_cond_wait(&t->sleep_cond, &t->sleep_mutex); assert(code == 0 || code == ETIMEDOUT); }}} -- Ticket URL: <http://www.macruby.org/trac/ticket/790#comment:1> MacRuby <http://macruby.org/>
#790: Exception is not generated when calls Thread.stop with only one thread. ----------------------------------+----------------------------------------- Reporter: watson1978@… | Owner: lsansonetti@… Type: defect | Status: closed Priority: blocker | Milestone: MacRuby 0.7 Component: MacRuby | Resolution: fixed Keywords: | ----------------------------------+----------------------------------------- Changes (by lsansonetti@…): * status: new => closed * resolution: => fixed * milestone: => MacRuby 0.7 Comment: Thanks for the ticket and patch, I committed it with a minor esthetic change in r4404. -- Ticket URL: <http://www.macruby.org/trac/ticket/790#comment:2> MacRuby <http://macruby.org/>
participants (1)
-
MacRuby