Hi,

At Sun, 2 Jan 2005 01:54:14 +0900,
Florian Gro? wrote in [ruby-core:04067]:
> This code:
> 
> threads = Array.new(100) { Thread.new { sleep } }
> loop do
>    threads.each do |thread|
>      Thread.new(thread) do |thread|
>        sleep(rand)
>        thread.send(:initialize) { caller }
>      end
>    end
> end

I think re-initialization of Thread would be too dangerous.


Index: eval.c =================================================================== RCS file: /cvs/ruby/src/ruby/eval.c,v retrieving revision 1.747 diff -U2 -p -r1.747 eval.c --- eval.c 16 Dec 2004 15:01:48 -0000 1.747 +++ eval.c 2 Jan 2005 14:33:50 -0000 @@ -11699,8 +11699,19 @@ rb_thread_initialize(thread, args) VALUE thread, args; { + rb_thread_t th; + if (!rb_block_given_p()) { rb_raise(rb_eThreadError, "must be called with a block"); } - return rb_thread_start_0(rb_thread_yield, args, rb_thread_check(thread)); + th = rb_thread_check(thread); + if (th->stk_max) { + NODE *node = th->node; + if (!node) { + rb_raise(rb_eThreadError, "already initialized thread"); + } + rb_raise(rb_eThreadError, "already initialized thread - %s:%d", + node->nd_file, nd_line(node)); + } + return rb_thread_start_0(rb_thread_yield, args, th); }
-- Nobu Nakada