红宝石 |线程 backtrace_locations()函数
Thread#backtrace_locations() : backtrace_locations()是一个 Thread 类方法,它返回目标线程的执行堆栈——一个包含回溯位置对象的数组。
Syntax: Thread.backtrace_locations()
Parameter: Thread values
Return: the execution stack for the target thread—an array containing backtrace location objects.
示例 #1:
# Ruby code for Thread.backtrace_locations() method
# declaring Thread
a = Thread.new { print "a"; Thread.stop; print "c" }
# backtrace_locations form
puts "Thread a backtrace_locations() form : #{a.backtrace_locations()}\n\n"
输出 :
Thread a backtrace_locations() form : []
示例 #2:
# Ruby code for Thread.backtrace_locations() method
# declaring Thread
a = Thread.new { puts "HI! I am learning to code"}
# backtrace_locations form
puts "Thread a backtrace_locations() form : #{a.backtrace_locations()}\n\n"
输出 :
Thread a backtrace_locations() form : []