Ruby | Thread alive? function
Last Updated :
09 Dec, 2019
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 :
a = Thread . new { print "a" ; Thread .stop; print "c" }
puts "Thread a alive?() form : #{a.alive?()}\n\n"
|
Output :
Thread a alive?() form : true
Example #2 :
a = Thread . new { puts "HI! I am learning to code" }
puts "Thread a alive?() form : #{a.alive?()}\n\n"
|
Output :
Thread a alive?() form : true
HI! I am learning to code
Share your thoughts in the comments
Please Login to comment...