6 ms·
does it have goroutine termination, i recently found out you need a runtime patch for it
by BeriV2 3mo ago
does it have goroutine termination, i recently found out you need a runtime patch for it
- ameliaquining 3mo agoWhat exactly do you mean by "goroutine termination"?
- tgv 3mo agoI suppose: a "go" returns an id, and then you call kill(id) to terminate it, as if it were a pthread or a process. In which case the answer is: no.
- ameliaquining 3mo agoNon-cooperatively terminating a shared-memory thread is an inherently unsafe thing to do, and basically every runtime that has an API for it regards it as a design mistake. See, e.g., https://docs.oracle.com/javase/8/docs/technotes/guides/concurrency/threadPrimitiveDeprecation.html https://docs.oracle.com/javase/8/docs/technotes/guides/concu... and https://learn.microsoft.com/en-us/windows/win32/api/processthreadsapi/nf-processthreadsapi-terminatethread#remarks https://learn.microsoft.com/en-us/windows/win32/api/processt.... (POSIX's pthread_cancel is somewhat different, and avoids some of the worst failure modes, but at the cost of not actually consistently killing the thread when you call it—and it still has a lot of problems besides that.) So I don't think Go is ever going to add this, nor should it. (Having the go statement return a handle that you can block on would of course be completely fine, but at this point they're probably not going to do that either.)
- deleted 3mo ago[deleted]
- robryan 3mo agoCan just pass it a context, cancel the context, and handle for it in the goroutine.
- dolmen 3mo agoThe rule is to start a goroutine only if you know how it will end. A goroutine that has to be killed (no other way to tell it to stop) is a bug.
- konart 3mo agoTerminated from the outside? No. The only way is to have a communication channel or a context that can be canceled and a proper handling of these.
- qwm 3mo agoYou can't terminate goroutines like individual threads, but there's no good reason to anyway. They designed the context system to be able to signal across goroutines and do cleanup that way
- JyB 3mo agoNo. You're down a very bad path if you 're seeking that.