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.


Similar Reads

Ruby | Thread backtrace_locations() function
Thread#backtrace_locations() : backtrace_locations() is a Thread class method which returns the execution stack for the target thread—an array containing backtrace location objects. Syntax: Thread.backtrace_locations() Parameter: Thread values Return: the execution stack for the target thread—an array containing backtrace location objects. Example
1 min read
Ruby | Thread abort_on_exception= function
Thread#abort_on_exception=() : abort_on_exception=() is a Thread class method which sets the raised exception to true or false Syntax: Thread.abort_on_exception=() Parameter: Thread values Return: sets the raised exception to true or false Example #1 : # Ruby code for Thread.abort_on_exception=() method # declaring Thread a = Thread.new { print
1 min read
Ruby | Thread abort_on_exception function
Thread#abort_on_exception() : abort_on_exception() is a Thread class method which returns the status of the thread-local "abort on exception" condition for this "thr". Syntax: Thread.abort_on_exception() Parameter: Thread values Return: The status of the thread-local "abort on exception" Default - False Example #1 : # Ruby code for Thread.abort_on_
1 min read
Ruby | Thread alive? function
Thread#alive?() : alive?() is a Thread class method which checks whether the thread is running or sleeping. Syntax: Thread.alive?() Parameter: Thread values Return: true - if running else false Example #1 : # Ruby code for Thread.alive?() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print "c" } # alive? for
1 min read
Ruby | Thread add_trace_func function
Thread#add_trace_func() : add_trace_func() is a Thread class method which adds process as a handler for tracing. Syntax: Thread.add_trace_func() Parameter: Thread values Return: adds process as a handler for tracing. Example #1 : # Ruby code for Thread.add_trace_func() method # declaring Thread a = Thread.new { print "a"; Thread.stop; pri
1 min read
Ruby | Thread backtrace function
Thread#backtrace() : backtrace() is a Thread class method which returns the current backtrace of the target thread. Syntax: Thread.backtrace() Parameter: Thread values Return: the current backtrace of the target thread. Example #1 : # Ruby code for Thread.backtrace() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print
1 min read
Ruby | Thread exit() function
Thread#exit() : exit() is a Thread class method which is used to terminates the thread and schedules another thread to be run. Syntax: Thread.exit() Parameter: Thread values Return: terminates the thread Example #1 : # Ruby code for Thread.exit() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print "c" } # ex
1 min read
Ruby | Thread kill() function
Thread#kill() : kill() is a Thread class method which is used to terminates the thread and schedules another thread to be run. Syntax: Thread.kill() Parameter: Thread values Return: terminates the thread Example#1 : # Ruby code for Thread.kill() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print "c" } # kil
1 min read
Ruby | Thread terminate() function
Thread#terminate() : terminate() is a Thread class method which is used to terminates the thread and schedules another thread to be run. Syntax: Thread.terminate() Parameter: Thread values Return: terminates the thread Example #1 : # Ruby code for Thread.terminate() method # declaring Thread a = Thread.new { print "a"; Thread.stop; print
1 min read
Ruby | Thread Class-Public Class Methods
In Ruby, threads are used to implement concurrent programming module. Programs that required multiple threads, use the Thread class to create threads. Thread class contains a wide range of methods that perform some specified tasks. Public Class Methods abort_on_exception : This method returns the status of the global "abort on exception" condition.
4 min read