July 2011
Intermediate to advanced
400 pages
8h 46m
English
Each thread has a status that may be one of the following:
| When the thread is executing |
| When the thread is sleeping or waiting on I/O |
| When the thread is aborting |
| When the thread terminated normally |
| When the thread terminated with an exception |
You can obtain the status of a thread using the status method. The status is also shown when you inspect a thread, in which case either a nil or a false status is shown as dead.
thread_status.rb
puts( Thread.main.inspect ) #=> #<Thread:0x28955c8 run> puts( Thread.new{ sleep }.kill.inspect ) #=> #<Thread:0x28cddc0 dead> puts( Thread.new{ sleep }.inspect ) #=> #<Thread:0x28cdd48 sleep> thread1 = Thread.new{ } puts( thread1.status ) #=> false thread2 = Thread.new{ raise( "Exception ...Read now
Unlock full access