packagemainimport ("fmt""sync")var total intvar wg sync.WaitGroupvar lock sync.Mutex// Inc increments the counter for the given key.funcinc(num int) { lock.Lock()defer lock.Unlock() total += num wg.Done()}// Value returns the current value of the counter for the given key.funcgetValue() int {return total}funcmain() {for i :=1; i <=1000; i++ { wg.Add(1)goinc(i) } wg.Wait() fmt.Println(getValue())}