Skip to content
Related Articles

Related Articles

Improve Article
Save Article
Like Article

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.

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!