Thread

class Thread

Parent:
Object

Threads are the Ruby implementation for a concurrent programming model.

Programs that require multiple threads of execution are a perfect candidate for Ruby's Thread class.

For example, we can create a new thread separate from the main thread's execution using ::new.

thr = Thread.new { puts "Whats the big deal" }

Then we are able to pause the execution of the main thread and allow our new thread to finish, using join:

thr.join #=> "Whats the big deal"

If we don't call thr.join before the main thread terminates, then all other threads including thr登录查看完整内容