Skip to content
Related Articles

Related Articles

Ruby | Thread exit() function
  • Last Updated : 09 Dec, 2019
GeeksforGeeks - Summer Carnival Banner

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" }
  
# exit form
puts "Thread a exit() form : #{a.exit()}\n\n"

Output :

Thread a exit() form : #

Example #2 :




# Ruby code for Thread.exit() method
  
# declaring Thread 
a = Thread.new { puts "HI! I am learning to code"}
  
# exit form
puts "Thread a exit() form : #{a.exit()}\n\n"

Output :

Thread a exit() form : #

Note :
The thread 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 :