1
2
3
4
5
12 package main
13
14 import (
15 "os"
16 "runtime/pprof"
17 "time"
18 )
19
20 func init() {
21 register("Etcd6857", Etcd6857)
22 }
23
24 type Status_etcd6857 struct{}
25
26 type node_etcd6857 struct {
27 status chan chan Status_etcd6857
28 stop chan struct{}
29 done chan struct{}
30 }
31
32 func (n *node_etcd6857) Status() Status_etcd6857 {
33 c := make(chan Status_etcd6857)
34 n.status <- c
35 return <-c
36 }
37
38 func (n *node_etcd6857) run() {
39 for {
40 select {
41 case c := <-n.status:
42 c <- Status_etcd6857{}
43 case <-n.stop:
44 close(n.done)
45 return
46 }
47 }
48 }
49
50 func (n *node_etcd6857) Stop() {
51 select {
52 case n.stop <- struct{}{}:
53 case <-n.done:
54 return
55 }
56 <-n.done
57 }
58
59 func NewNode_etcd6857() *node_etcd6857 {
60 return &node_etcd6857{
61 status: make(chan chan Status_etcd6857),
62 stop: make(chan struct{}),
63 done: make(chan struct{}),
64 }
65 }
66
67 func Etcd6857() {
68 prof := pprof.Lookup("goroutineleak")
69 defer func() {
70 time.Sleep(100 * time.Millisecond)
71 prof.WriteTo(os.Stdout, 2)
72 }()
73 for i := 0; i <= 100; i++ {
74 go func() {
75 n := NewNode_etcd6857()
76 go n.run()
77 go n.Status()
78 go n.Stop()
79 }()
80 }
81 }
82
View as plain text