Created
February 2, 2019 06:51
-
-
Save zhyon404/21e257d833bfbdd59f709a6dc5b9c79d 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
func Test_double_check_unsafe(t *testing.T) { | |
m := make(map[int]int64) | |
mu := sync.Mutex{} | |
wg := sync.WaitGroup{} | |
wg.Add(100 * 10) | |
for i := 0; i < 100; i++ { | |
for j := 0; j < 10; j++ { | |
go func(j int) { | |
defer wg.Done() | |
v := m[j] | |
if v != 0 { | |
return | |
} | |
mu.Lock() | |
defer mu.Unlock() | |
mm := make(map[int]int64) | |
mm[j] = 1 | |
m = mm | |
}(1) | |
} | |
} | |
wg.Wait() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
WARNING: DATA RACE