Created
September 3, 2017 16:23
-
-
Save AlexeySoshin/89b53d9bfd6a70014a00774af8632f55 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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