Open In App

Ruby | Thread terminate() function

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

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


Output :

Thread a terminate() form : #

Example #2 :




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


Output :

Thread a terminate() 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.


Like Article
Suggest improvement
Previous
Next
Share your thoughts in the comments

Similar Reads