Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Created September 3, 2017 16:25
Show Gist options
  • Save AlexeySoshin/9842afae3bdd577730e4325d14e47f7d to your computer and use it in GitHub Desktop.
Save AlexeySoshin/9842afae3bdd577730e4325d14e47f7d to your computer and use it in GitHub Desktop.
m := make(map[float64]float64)
// Create mutex manually
mux := sync.Mutex{}
doneChannel := make(chan bool, 10)
for i := 0; i < 10; i++ {
go func() {
for i := 0; i < 1000; i++ {
f := rand.Float64()
// Lock and unlock
mux.Lock()
m[f] = f
mux.Unlock()
}
doneChannel <- true
}()
}
for i := 0; i < 10; i++ {
<-doneChannel
}
// That's better: 10000
fmt.Println(len(m))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment