Source file
test/ken/chan1.go
1
2
3
4
5
6
7
8
9 package main
10
11 import "runtime"
12
13 const N = 1000
14 const M = 10
15 const W = 2
16 var h [N]int
17
18 func r(c chan int, m int) {
19 for {
20 select {
21 case r := <-c:
22 if h[r] != 1 {
23 println("r",
24 "m=", m,
25 "r=", r,
26 "h=", h[r])
27 panic("fail")
28 }
29 h[r] = 2
30 }
31 }
32 }
33
34 func s(c chan int) {
35 for n := 0; n < N; n++ {
36 r := n
37 if h[r] != 0 {
38 println("s")
39 panic("fail")
40 }
41 h[r] = 1
42 c <- r
43 }
44 }
45
46 func main() {
47 c := make(chan int, W)
48 for m := 0; m < M; m++ {
49 go r(c, m)
50 runtime.Gosched()
51 }
52 runtime.Gosched()
53 runtime.Gosched()
54 s(c)
55 }
56
View as plain text