Skip to content
class method

Thread.new

(*untyped) { (?) -> void } -> ::Thread
Thread.new { ... } → thread
Thread.new(*args, &proc) → thread
Thread.new(*args) { |args| ... } → thread

Creates a new thread executing the given block.

Any args given to ::new will be passed to the block:

Example
arr = []
a, b, c = 1, 2, 3
Thread.new(a,b,c) { |d,e,f| arr << d << e << f }.join
arr #=> [1, 2, 3]

A ThreadError exception is raised if ::new is called without a block.

If you’re going to subclass Thread, be sure to call super in your initialize method, otherwise a ThreadError will be raised.

See also .main .pass .list .pending_interrupt? also in 4.1 · 3.4 · 3.3 · 3.2 · 3.1 · 3.0