fix: data race when go func() in for loop
This commit is contained in:
parent
a3647f8e31
commit
386f0be94b
|
@ -1563,9 +1563,10 @@ func benchmarkCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(n)
|
wg.Add(n)
|
||||||
for _, v := range keys {
|
for _, v := range keys {
|
||||||
|
k := v
|
||||||
go func() {
|
go func() {
|
||||||
for j := 0; j < each; j++ {
|
for j := 0; j < each; j++ {
|
||||||
tc.Get(v)
|
tc.Get(k)
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
|
@ -7,9 +7,6 @@ import (
|
||||||
"time"
|
"time"
|
||||||
)
|
)
|
||||||
|
|
||||||
// func TestDjb33(t *testing.T) {
|
|
||||||
// }
|
|
||||||
|
|
||||||
var shardedKeys = []string{
|
var shardedKeys = []string{
|
||||||
"f",
|
"f",
|
||||||
"fo",
|
"fo",
|
||||||
|
@ -73,9 +70,10 @@ func benchmarkShardedCacheGetManyConcurrent(b *testing.B, exp time.Duration) {
|
||||||
wg := new(sync.WaitGroup)
|
wg := new(sync.WaitGroup)
|
||||||
wg.Add(n)
|
wg.Add(n)
|
||||||
for _, v := range keys {
|
for _, v := range keys {
|
||||||
|
k := v
|
||||||
go func() {
|
go func() {
|
||||||
for j := 0; j < each; j++ {
|
for j := 0; j < each; j++ {
|
||||||
tsc.Get(v)
|
tsc.Get(k)
|
||||||
}
|
}
|
||||||
wg.Done()
|
wg.Done()
|
||||||
}()
|
}()
|
||||||
|
|
Loading…
Reference in New Issue