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