-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgoroutines_and_channels.slide
100 lines (53 loc) · 2.17 KB
/
goroutines_and_channels.slide
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
Goroutines and channels - simple, but powerful tools in Go arsenal
15 mar 2016
* About me
Krzysztof Kwapisiewicz, Software Developer at CodiLime
@kwapik
github.com/kwapik/goroutines-and-channels-talk
.image img/codilime.jpg 200 _
* References
- [[https://www.youtube.com/watch?v=f6kdp27TYZs]["Go Concurrency Patterns"]] by Rob Pike
- [[https://golang.org/doc/effective_go.html#concurrency][Effective Go]]
- 1 year of relationship with Gopher
.image img/gopher.png 200 _
* Goroutines
Independently executing function, launched by a Go statement.
Has own call stack which grows and shrinks as required.
Very cheap. Do not be afraid to run 5 digit number of them.
Multiplexed onto multiple OS thread.
* Life without goroutines
.play examples/no_goroutines.go /START OMIT/,/END OMIT/
* Goroutines - simple_example
.play examples/goroutines_simple.go /START OMIT/,/END OMIT/
* Goroutines - hotfix/simple_example
.play examples/goroutines_simple_fixed.go /START OMIT/,/END OMIT/
* Goroutines - simple_example TODO
Waiting is not very reliable way to ensure goroutine finished all important stuff.
We want to exchange information.
* Channels
Provide connection between goroutines so they can communicate.
.code examples/channels_simple.go /START OMIT/,/END OMIT/
.code examples/channels_buffered.go /START OMIT/,/END OMIT/
* Synchronization
.play examples/channels_synchronization.go /START OMIT/,/END OMIT/
* Multiple channels
.play examples/channels_multiple.go /START OMIT/,/END OMIT/
* Multiple channels with select
.play examples/channels_select.go /START OMIT/,/END OMIT/
* Timeout single operation
.play examples/timeout.go /START OMIT/,/END OMIT/
* Timeout all operations
.play examples/timeout_all.go /START OMIT/,/END OMIT/
* Unlimited workers
.play examples/workers.go /START OMIT/,/END OMIT/
* Limited workers
.play examples/workers_limited.go /START OMIT/,/END OMIT/
* Results
.play examples/workers_results.go /START OMIT/,/END OMIT/
* Killing result reader
.play examples/workers_kill.go /START OMIT/,/END OMIT/
* How fast it can go?
.image img/whisper.jpg
* How fast it can go? - code
.play examples/whisper.go /START OMIT/,/END OMIT/