📜  红宝石 |线程活着?函数

📅  最后修改于: 2022-05-13 01:55:38.560000             🧑  作者: Mango

红宝石 |线程活着?函数

Thread#alive?() :alive?()是一个 Thread 类方法,用于检查线程是在运行还是在休眠。

示例 #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