var n int32 = 0
var mutex *sync.Mutex = new(sync.Mutex)
for i := 0; i < 100000; i++ {
go func() {
mutex.Lock()
defer mutex.Unlock()
atomic.AddInt32(&n, 1)
}()
}
fmt.Println(n)
I'm wondering why the result of n is not 100000, looks like the mutex lock does not work.