1
2
3
4
5
16
17 package main
18
19 import (
20 "context"
21 "os"
22 "runtime/pprof"
23 "time"
24 )
25
26 func init() {
27 register("Cockroach10790", Cockroach10790)
28 }
29
30 type Replica_cockroach10790 struct {
31 chans []chan bool
32 }
33
34 func (r *Replica_cockroach10790) beginCmds(ctx context.Context) {
35 ctxDone := ctx.Done()
36 for _, ch := range r.chans {
37 select {
38 case <-ch:
39 case <-ctxDone:
40 go func() {
41 for _, ch := range r.chans {
42 <-ch
43 }
44 }()
45 }
46 }
47 }
48
49 func (r *Replica_cockroach10790) sendChans(ctx context.Context) {
50 for _, ch := range r.chans {
51 select {
52 case ch <- true:
53 case <-ctx.Done():
54 return
55 }
56 }
57 }
58
59 func NewReplica_cockroach10790() *Replica_cockroach10790 {
60 r := &Replica_cockroach10790{}
61 r.chans = append(r.chans, make(chan bool), make(chan bool))
62 return r
63 }
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82 func Cockroach10790() {
83 prof := pprof.Lookup("goroutineleak")
84 defer func() {
85 time.Sleep(100 * time.Millisecond)
86 prof.WriteTo(os.Stdout, 2)
87 }()
88
89 for i := 0; i < 100; i++ {
90 go func() {
91 r := NewReplica_cockroach10790()
92 ctx, cancel := context.WithCancel(context.Background())
93 go r.sendChans(ctx)
94 go r.beginCmds(ctx)
95 go cancel()
96 }()
97 }
98 }
99
View as plain text