红宝石 |线程组()函数
Thread#group() : group()是一个 Thread 类方法,它返回包含给定线程的 ThreadGroup,如果线程不是任何组的成员,则返回 nil。
Syntax: Thread.group()
Parameter: Thread values
Return: the ThreadGroup which contains the given thread
nil – if thread is not a member of any group.
示例 #1:
# Ruby code for Thread.group() method
# declaring Thread
a = Thread.new { print "a"; Thread.stop; print "c" }
# group form
puts "Thread a group() form : #{a.group()}\n\n"
输出 :
Thread a group() form : #
示例 #2:
# Ruby code for Thread.group() method
# declaring Thread
a = Thread.new { puts "HI! I am learning to code"}
# group form
puts "Thread a group() form : #{a.group()}\n\n"
输出 :
Thread a group() form : #
笔记 :
输出中生成的 ThreadGroup 对象取决于系统和指针值。因此,每次运行代码时它可能会有所不同。