Basic Thread Semantics

suggest change

A new thread, separate from the main thread’s execution, can be created with Thread.new.

thr = Thread.new {
  sleep 1 # 1 second sleep of sub thread
  puts "What's the big deal"
}

This will automatically start the execution of the new thread.

To wait until the new thread stops before the main thread continues, use join:

thr.join #=> ... "What's the big deal"

The thread may already have finished when you call join, in which case execution continues normally. If a sub-thread is never joined and the main thread finishes, the sub-thread does not run any remaining code.

Feedback about page:

Feedback:
Optional: your email if you want me to get back to you:



Table Of Contents