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