-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdop_2.go
100 lines (74 loc) · 1.38 KB
/
dop_2.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"fmt"
"sync"
)
var m sync.RWMutex
type calling interface {
callName() string
callProfession() string
callPosition() string
}
type head struct {
pers *human
dept string
}
type worker struct {
pers *human
exp int
position string
}
type human struct {
name string
age int
}
type cache struct {
m map[int]calling
}
type cacheWorker map[int]worker
type cacheHead map[int]head
func (q worker) toHuman() human {
res := (*q.pers)
return res
}
func (c *cacheWorker) call(wg *sync.WaitGroup) {
fmt.Println("worker_map")
for _, v := range *c {
fmt.Println(v)
}
wg.Done()
m.Unlock()
}
func (c *cacheHead) call(wg *sync.WaitGroup) {
fmt.Println("head_map")
for _, v := range *c {
fmt.Println(v)
}
wg.Done()
m.Unlock()
}
func main() {
q := worker{&human{"John", 24}, 1, "junior"}
fmt.Println(q.toHuman())
cWorker := make(cacheWorker)
cHead := make(cacheHead)
q1 := worker{&human{"John", 24}, 1, "junior"}
q2 := worker{&human{"Jack", 26}, 3, "middle"}
q3 := worker{&human{"Mike", 23}, 2, "junior"}
cWorker[1] = q1
cWorker[2] = q2
cWorker[3] = q3
p1 := head{&human{"Mary", 35}, "sales"}
p2 := head{&human{"George", 40}, "development"}
p3 := head{&human{"Jack", 36}, "hr"}
cHead[1] = p1
cHead[2] = p2
cHead[3] = p3
var wg sync.WaitGroup
wg.Add(2)
m.Lock()
go cHead.call(&wg)
m.Lock()
go cWorker.call(&wg)
wg.Wait()
}