Created
September 3, 2017 16:25
-
-
Save AlexeySoshin/9842afae3bdd577730e4325d14e47f7d 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
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