File tree Expand file tree Collapse file tree 5 files changed +20
-9
lines changed
05_blank-identifier/02_http-get_example
21_interfaces/01_interface/02_interface
22_go-routines/13_channels_fan-out_fan-in/05_challenge-solution Expand file tree Collapse file tree 5 files changed +20
-9
lines changed Original file line number Diff line number Diff line change 44 "fmt"
55 "github.com/GoesToEleven/GolangTraining/02_package/stringutil"
66 "github.com/GoesToEleven/GolangTraining/02_package/icomefromalaska"
7+ //someAlias "github.com/GoesToEleven/GolangTraining/02_package/icomefromalaska"
78)
89
910func main () {
Original file line number Diff line number Diff line change 88)
99
1010func main () {
11- res , err := http .Get ("http://www.mcleods .com/" )
11+ res , err := http .Get ("http://www.geekwiseacademy .com/" )
1212 if err != nil {
1313 log .Fatal (err )
1414 }
Original file line number Diff line number Diff line change 77)
88
99func main () {
10- res , _ := http .Get ("http://www.mcleods .com/" )
10+ res , _ := http .Get ("http://www.geekwiseacademy .com/" )
1111 page , _ := ioutil .ReadAll (res .Body )
1212 res .Body .Close ()
1313 fmt .Printf ("%s" , page )
14- }
14+ }
Original file line number Diff line number Diff line change @@ -21,5 +21,6 @@ func info(z shape) {
2121
2222func main () {
2323 s := square {10 }
24+ fmt .Printf ("%T\n " ,s )
2425 info (s )
2526}
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ package main
33import (
44 "fmt"
55 "time"
6+ "sync/atomic"
67)
78
8- var workerID int
9- var publisherID int
9+ var workerID int64
10+ var publisherID int64
1011
1112func main () {
1213 input := make (chan string )
@@ -22,8 +23,12 @@ func main() {
2223
2324// publisher pushes data into a channel
2425func publisher (out chan string ) {
25- publisherID ++
26- thisID := publisherID
26+ atomic .AddInt64 (& publisherID , 1 )
27+ // atomic was added after recording to fix a race condition
28+ // discover race conditions with the -race flag
29+ // for example: go run -race main.go
30+ // learn about the atomic package: https://godoc.org/sync/atomic#AddInt64
31+ thisID := atomic .LoadInt64 (& publisherID )
2732 dataID := 0
2833 for {
2934 dataID ++
@@ -34,8 +39,12 @@ func publisher(out chan string) {
3439}
3540
3641func workerProcess (in <- chan string ) {
37- workerID ++
38- thisID := workerID
42+ atomic .AddInt64 (& workerID , 1 )
43+ // atomic was added after recording to fix a race condition
44+ // discover race conditions with the -race flag
45+ // for example: go run -race main.go
46+ // learn about the atomic package: https://godoc.org/sync/atomic#AddInt64
47+ thisID := atomic .LoadInt64 (& workerID )
3948 for {
4049 fmt .Printf ("%d: waiting for input...\n " , thisID )
4150 input := <- in
You can’t perform that action at this time.
0 commit comments