Ruby 线程 exit()函数
Thread#exit() : exit()是Thread类的一个方法,用于终止线程并安排另一个线程的运行。
语法。Thread.exit()
参数。线程值
返回:终止该线程
例子 #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 : #
注:
输出中生成的线程对象取决于系统和指针值。因此,每次运行代码时,它可能会有所不同。