I am just learning about mutexess. I thought the following program would return a total of 1000, but I am getting varied results, so I assume I am doing something wrong...
package main
import (
"fmt"
"sync"
)
var total int
var locker sync.RWMutex
func add() {
for x := 1; x <= 100; x++ {
locker.Lock()
total += 1
locker.Unlock()
}
}
func main() {
for x := 1; x <= 10; x++ {
go add()
}
fmt.Printf("Total is %v
", total)
}