Skip to content

Instantly share code, notes, and snippets.

@AlexeySoshin
Created September 3, 2017 16:23
Show Gist options
  • Save AlexeySoshin/89b53d9bfd6a70014a00774af8632f55 to your computer and use it in GitHub Desktop.
Save AlexeySoshin/89b53d9bfd6a70014a00774af8632f55 to your computer and use it in GitHub Desktop.
// There's no proper UUID package still, so we'll deal with floats
m := make(map[float64]float64)
// This will allow us to wait for all goroutines to complete
doneChannel := make(chan bool, 10)
// Launch goroutines
for i := 0; i < 10; i++ {
go func() {
// Generate some random numbers
for i := 0; i < 1000; i++ {
f := rand.Float64()
m[f] = f
}
// Notify when done
doneChannel <- true
}()
}
// Wait
for i := 0; i < 10; i++ {
<-doneChannel
}
// Crash! fatal error: concurrent map writes!
fmt.Println(len(m))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment