[MacRuby-devel] [MacRuby] #790: Exception is not generated when calls Thread.stop with only one thread.

MacRuby ruby-noreply at macosforge.org
Wed Aug 4 01:08:49 PDT 2010


#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/>



More information about the MacRuby-devel mailing list