Ruby 线程 alive?函数
Thread#alive?() : alive?() 是Thread类的一个方法,用于检查线程是在运行还是在睡觉。
语法。Thread.alive?()
参数。线程值
返回:true – 如果正在运行 ,否则为false
例子 #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"
输出:
Thread a alive?() form : true
例子 #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"
输出:
Thread a alive?() form : true
HI! I am learning to code