Basic Thread Semantics
suggest changeA 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.
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents