当前位置: 首页>>代码示例 >>用法及示例精选 >>正文


Ruby Thread alive?用法及代码示例


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

用法:Thread.alive?()

参数:线程值


返回:true-如果正在运行
否则错误

范例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


相关用法


注:本文由纯净天空筛选整理自mayank5326大神的英文原创作品 Ruby | Thread alive? function。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。