Skip to content
Related Articles
Get the best out of our app
GeeksforGeeks App
Open App
geeksforgeeks
Browser
Continue

Related Articles

Ruby | Thread kill() function

Improve Article
Save Article
Like Article
Improve Article
Save Article
Like Article

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

Output :

Thread a kill() form : #

Example #2 :




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

Output :

Thread a kill() 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
Last Updated : 06 Dec, 2019
Like Article
Save Article
Similar Reads