1)golang如何解决可见性问题?
2)以下代码是否存在任何问题?
package main
type Service struct {
stop bool
}
func (s *Service) Run() {
for !s.stop {
//Some logic
}
}
func (s *Service) Stop() {
s.stop = true
}
func main() {
s := &Service{}
go s.Run()
//Some logic
s.Stop()
}