4 ms·
does it have goroutine termination, i recently found out you need a runtime patch for it
by BeriV2 2mo ago
does it have goroutine termination, i recently found out you need a runtime patch for it
- ameliaquining 2mo agoWhat exactly do you mean by "goroutine termination"?
- tgv 2mo 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 2mo 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 1mo ago[deleted]
- robryan 1mo agoCan just pass it a context, cancel the context, and handle for it in the goroutine.
- dolmen 1mo 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 1mo 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 1mo 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 1mo agoNo. You're down a very bad path if you 're seeking that.