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 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


Output :

Thread a exit() form : #

Example #2 :

filter_none

edit
close

play_arrow

link
brightness_4
code

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

chevron_right


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.



My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :

Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.