Method: Thread.new

Defined in:
eval.c

.new([arg]) {|args| ... } ⇒ Object

Creates and runs a new thread to execute the instructions given in block. Any arguments passed to Thread::new 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...

produces:

abxyzc

Yields:

  • (args)


11981
11982
11983
# File 'eval.c', line 11981

static VALUE
rb_thread_s_new(argc, argv, klass)
int argc;