LEFT | RIGHT |
(no file at all) | |
1 // Copyright 2012 The Go Authors. All rights reserved. | 1 // Copyright 2012 The Go Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style | 2 // Use of this source code is governed by a BSD-style |
3 // license that can be found in the LICENSE file. | 3 // license that can be found in the LICENSE file. |
4 | 4 |
5 package race_test | 5 package race_test |
6 | 6 |
7 import ( | 7 import ( |
8 "testing" | 8 "testing" |
9 ) | 9 ) |
10 | 10 |
11 func TestRaceMapRW(t *testing.T) { | 11 func TestRaceMapRW(t *testing.T) { |
12 m := make(map[int]int) | 12 m := make(map[int]int) |
13 ch := make(chan bool, 1) | 13 ch := make(chan bool, 1) |
14 go func() { | 14 go func() { |
15 _ = m[1] | 15 _ = m[1] |
16 ch <- true | 16 ch <- true |
17 }() | 17 }() |
18 m[1] = 1 | 18 m[1] = 1 |
19 <-ch | 19 <-ch |
20 } | 20 } |
21 | 21 |
22 func TestRaceMapRW2(t *testing.T) { | 22 func TestRaceMapRW2(t *testing.T) { |
23 m := make(map[int]int) | 23 m := make(map[int]int) |
24 ch := make(chan bool, 1) | 24 ch := make(chan bool, 1) |
25 go func() { | 25 go func() { |
26 _, _ = m[1] | 26 _, _ = m[1] |
27 ch <- true | 27 ch <- true |
28 }() | 28 }() |
29 m[1] = 1 | 29 m[1] = 1 |
| 30 <-ch |
| 31 } |
| 32 |
| 33 func TestRaceMapRWStrByte(t *testing.T) { |
| 34 m := make(map[string]int) |
| 35 ch := make(chan bool, 1) |
| 36 key := []byte("key") |
| 37 go func() { |
| 38 _ = m[string(key)] |
| 39 ch <- true |
| 40 }() |
| 41 m[string(key)] = 1 |
| 42 <-ch |
| 43 } |
| 44 |
| 45 func TestRaceMapRW2StrByte(t *testing.T) { |
| 46 m := make(map[string]int) |
| 47 ch := make(chan bool, 1) |
| 48 key := []byte("key") |
| 49 go func() { |
| 50 _, _ = m[string(key)] |
| 51 ch <- true |
| 52 }() |
| 53 m[string(key)] = 1 |
30 <-ch | 54 <-ch |
31 } | 55 } |
32 | 56 |
33 func TestRaceMapRWArray(t *testing.T) { | 57 func TestRaceMapRWArray(t *testing.T) { |
34 // Check instrumentation of unaddressable arrays (issue 4578). | 58 // Check instrumentation of unaddressable arrays (issue 4578). |
35 m := make(map[int][2]int) | 59 m := make(map[int][2]int) |
36 ch := make(chan bool, 1) | 60 ch := make(chan bool, 1) |
37 go func() { | 61 go func() { |
38 _ = m[1][1] | 62 _ = m[1][1] |
39 ch <- true | 63 ch <- true |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
152 func TestRaceMapVariable3(t *testing.T) { | 176 func TestRaceMapVariable3(t *testing.T) { |
153 ch := make(chan bool, 1) | 177 ch := make(chan bool, 1) |
154 m := make(map[int]int) | 178 m := make(map[int]int) |
155 go func() { | 179 go func() { |
156 _ = m[1] | 180 _ = m[1] |
157 ch <- true | 181 ch <- true |
158 }() | 182 }() |
159 m = make(map[int]int) | 183 m = make(map[int]int) |
160 <-ch | 184 <-ch |
161 } | 185 } |
LEFT | RIGHT |