How to kill a goroutine

1,136 views
Skip to first unread message

Baron Schwartz

unread,
Dec 27, 2013, 10:38:00 AM12/27/13
to golan...@googlegroups.com
Is there a way to cause a goroutine to stop? Imagine I'm a supervisor goroutine and I know about a bunch of worker goroutines. I decide that one of them is out of control and I want to kill it. Can I do that?

I know of some techniques to "ask" or "invite" it to exit, such as making it check for a value on a channel and exit if there is one. But I don't want to ask it, and I don't want to wait until it notices I've asked; I want to kill-dash-nine it. Or, given that it could defer/recover catch a panic, at least kill-dash-fifteen :-)

Thanks
Baron

Jan Mercl

unread,
Dec 27, 2013, 10:41:35 AM12/27/13
to Baron Schwartz, golang-nuts

A goroutine cannot be programmatically killed. It can only commit a cooperative suicide.

-j

Baron Schwartz

unread,
Dec 27, 2013, 10:42:20 AM12/27/13
to golan...@googlegroups.com
On Friday, December 27, 2013 10:38:00 AM UTC-5, Baron Schwartz wrote:
Is there a way to cause a goroutine to stop? Imagine I'm a supervisor goroutine and I know about a bunch of worker goroutines. I decide that one of them is out of control and I want to kill it. Can I do that?

Graham Miller

unread,
Dec 27, 2013, 11:12:29 AM12/27/13
to Baron Schwartz, golang-nuts

--
You received this message because you are subscribed to the Google Groups "golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email to golang-nuts...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages