We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
程序优雅的退时。使用了原子操作atomic.CompareAndSwapInt32 。atomic.LoadInt32; 原子操作在这里起到的作用是?或者说:为什么退出这里引入了 atomic 期待你的指导。谢谢
`func Run(ctx context.Context, opts ...Option) error { var state int32 = 1 sc := make(chan os.Signal, 1) signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT) cleanFunc, err := Init(ctx, opts...) if err != nil { return err }
EXIT: for { sig := <-sc logger.Printf(ctx, "接收到信号[%s]", sig.String()) switch sig { case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT: atomic.CompareAndSwapInt32(&state, 1, 0) break EXIT case syscall.SIGHUP: default: break EXIT } }
cleanFunc() logger.Printf(ctx, "服务退出") time.Sleep(time.Second) os.Exit(int(atomic.LoadInt32(&state))) return nil
}`
The text was updated successfully, but these errors were encountered:
No branches or pull requests
程序优雅的退时。使用了原子操作atomic.CompareAndSwapInt32 。atomic.LoadInt32;
原子操作在这里起到的作用是?或者说:为什么退出这里引入了 atomic
期待你的指导。谢谢
`func Run(ctx context.Context, opts ...Option) error {
var state int32 = 1
sc := make(chan os.Signal, 1)
signal.Notify(sc, syscall.SIGHUP, syscall.SIGINT, syscall.SIGTERM, syscall.SIGQUIT)
cleanFunc, err := Init(ctx, opts...)
if err != nil {
return err
}
EXIT:
for {
sig := <-sc
logger.Printf(ctx, "接收到信号[%s]", sig.String())
switch sig {
case syscall.SIGQUIT, syscall.SIGTERM, syscall.SIGINT:
atomic.CompareAndSwapInt32(&state, 1, 0)
break EXIT
case syscall.SIGHUP:
default:
break EXIT
}
}
}`
The text was updated successfully, but these errors were encountered: