/* * call-seq: * Thread.new([arg]*) {|args| block } => thread * * Creates and runs a new thread to execute the instructions given in * <i>block</i>. Any arguments passed to <code>Thread::new</code> are passed * into the block. * * x = Thread.new { sleep 0.1; print "x"; print "y"; print "z" } * a = Thread.new { print "a"; print "b"; sleep 0.2; print "c" } * x.join # Let the threads finish before * a.join # main thread exits... * * <em>produces:</em> * * abxyzc */ static VALUE 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"); } 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); }