Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Thread alive? function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

Thread#alive?() : alive?() is a Thread class method which checks whether the thread is running or sleeping.

Syntax: Thread.alive?()

Parameter: Thread values

Return: true – if running
else false

Example #1 :




# Ruby code for Thread.alive?() method
  
# declaring Thread 
a = Thread.new { print "a"; Thread.stop; print "c" }
  
# alive? form
puts "Thread a alive?() form : #{a.alive?()}\n\n"

Output :

Thread a alive?() form : true

Example #2 :




# Ruby code for Thread.alive?() method
  
# declaring Thread 
a = Thread.new { puts "HI! I am learning to code"}
  
# alive? form
puts "Thread a alive?() form : #{a.alive?()}\n\n"

Output :

Thread a alive?() form : true

HI! I am learning to code
My Personal Notes arrow_drop_up
Last Updated : 09 Dec, 2019
Like Article
Save Article
Similar Reads