| 1 |
// skip |
| 2 |
|
| 3 |
// Copyright 2019 The Go Authors. All rights reserved. |
| 4 |
// Use of this source code is governed by a BSD-style |
| 5 |
// license that can be found in the LICENSE file. |
| 6 |
|
| 7 |
package main |
| 8 |
|
| 9 |
import ( |
| 10 |
"fmt" |
| 11 |
"time" |
| 12 |
) |
| 13 |
|
| 14 |
func main() { |
| 15 |
// Make a big map. |
| 16 |
m := map[int]int{} |
| 17 |
for i := 0; i < 100000; i++ { |
| 18 |
m[i] = i |
| 19 |
} |
| 20 |
c := make(chan string) |
| 21 |
go func() { |
| 22 |
// Print the map. |
| 23 |
s := fmt.Sprintln(m) |
| 24 |
c <- s |
| 25 |
}() |
| 26 |
go func() { |
| 27 |
time.Sleep(1 * time.Millisecond) |
| 28 |
// Add an extra item to the map while iterating. |
| 29 |
m[-1] = -1 |
| 30 |
c <- "" |
| 31 |
}() |
| 32 |
<-c |
| 33 |
<-c |
| 34 |
} |