On Wed, Feb 15, 2017 at 12:35 AM,  <su...@kync.com> wrote:
>
> I have a situation that need some advice. I have a main loop that is calling
> some C code (potentially looping forever).  and I need to handle signals
> like SIGABRT correctly by ensuring a cleanup function was run.
>
> func main() {
>
>   cleanup := func() {}
>   defer cleanup()
>
>   for {
>      C.do_something()
>   }
>
> }
>
> now , this works for synchronous signal / or anything caused by C code,
> because they will generate runtime panic on main thread, and deferred
> cleanup function will run.
>
> However, if I send signal through kill, the signal arrived in another
> thread, and apparently , main()'s defered functions  was never called , how
> do I catch that situation ?   I tried with a custom signal handler, but
> since I am busy looping in C code, I can't invoke panic() on the main
> thread.

Use the os/signal package.

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.

Reply via email to