Skip to content
Related Articles

Related Articles

Ruby | Thread group() function
  • Last Updated : 06 Dec, 2019

Thread#group() : group() is a Thread class method which returns the ThreadGroup which contains the given thread, or returns nil if thread is not a member of any group.

Syntax: Thread.group()

Parameter: Thread values

Return: the ThreadGroup which contains the given thread
nil – if thread is not a member of any group.

Example #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"

Output :

Thread a group() form : #

Example #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"

Output :

Thread a group() form : #

Note :
The ThreadGroup object generated in the output depends on the system and pointer value. So, it may vary each time the code is run.

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :