You might also want to consider running the stuff in a separate process. But honestly, you can't really be sure anyway, for asynchronous signals, because they are - as the name suggest - asynchronous. Between you calling kill and the signal actually being delivered and interrupting the process, it can just continue as it where.
On Wed, Feb 15, 2017 at 7:11 PM, Yucong Sun <sunyuc...@gmail.com> wrote: > In single threaded C code, The interrupter loop is guaranteed stop > when crash() is executing, Now in Go code, however, the interrupter > loop could still be executing when crash() is running. because there > is no way to interrupt a go routine beside a panic(), but like you > said, i can't induce panic on another go routine, so I can't do what i > want. > > Now, I get what you are saying, I need to invest some time on C code's > main loop to make it interruptible by other thread . which maybe what > I need to do. > > On Wed, Feb 15, 2017 at 10:56 AM, Ian Lance Taylor <i...@golang.org> > wrote: > > On Wed, Feb 15, 2017 at 10:43 AM, Yucong Sun <sunyuc...@gmail.com> > wrote: > >> So, to give more background, i am trying to porting a C based > >> interpreter to Go. In the single threaded C code, the signal is > >> always handled by interrupting whatever code was executing and > >> directly exit after executing some "crash()" cleanup function. > > > > Why can't you do exactly that in Go? > > > > > >> Now, I ported the main function to Go, as I demonstrated above, there > >> is no way to "interrupt" C code anymore, so I can't run crash() > >> cleanly as before. This seems to be a limitation of Go, and I couldn't > >> think of any way to work around it. > > > > If you want to implement the precise behavior of a single-threaded C > > program, then you need to write a single-threaded Go program. But > > that goal is clearly folly. Don't try to write C code in Go. When > > you are using Go, write Go code. That means: arrange your program as > > a Go program. > > > > Ian > -- 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+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.