I am not sure why the following code has the race condition, can someone give me a hint? I think there is no potential race condition. Thank you in advance.
type PossiblySafeCounter struct {
mu sync.Mutex
sum int
}
func (c *PossiblySafeCounter) inc() {
c.mu.Lock();
defer c.mu.Unlock();
go func() {
c.sum++
}()
}
func (c *PossiblySafeCounter) read() int {
c.mu.Lock();
defer c.mu.Unlock();
return c.sum
}