Open In App

Ruby | Thread group() function

Last Updated : 06 Dec, 2019
Improve
Improve
Like Article
Like
Save
Share
Report

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.


Like Article
Suggest improvement
Share your thoughts in the comments

Similar Reads