红宝石 |线程 kill()函数
Thread#kill() : kill()是一个 Thread 类方法,用于终止线程并安排另一个线程运行。
Syntax: Thread.kill()
Parameter: Thread values
Return: terminates the thread
示例#1:
# Ruby code for Thread.kill() method
# declaring Thread
a = Thread.new { print "a"; Thread.stop; print "c" }
# kill form
puts "Thread a kill() form : #{a.kill()}\n\n"
输出 :
Thread a kill() form : #
示例 #2:
# Ruby code for Thread.kill() method
# declaring Thread
a = Thread.new { puts "HI! I am learning to code"}
# kill form
puts "Thread a kill() form : #{a.kill()}\n\n"
输出 :
Thread a kill() form : #
笔记 :
输出中生成的线程对象取决于系统和指针值。因此,每次运行代码时它可能会有所不同。