Concurrency in Go Chapter1 (2)

package mainimport (
"fmt"
)
func main() {
var data int
go func() {
data++
}()
if data == 0 {
fmt.Printf("the value is %v.\n", data)
}
}
  1. writeが先に実行されれば、何も表示されない
  2. readが先に実行されれば、”the value is 0"と表示される
  3. readとfmt.Printfの間にwriteが実行されれば、”the value is 1"と表示される

--

--

--

Software engineer

Love podcasts or audiobooks? Learn on the go with our new app.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Takanori Ishibashi

Takanori Ishibashi

Software engineer

More from Medium

Go: How I learned to stop worrying and switch Programming Languages

3 ways to tackle the longest increasing subsequence problem(Golang)

Shadowing or how to fix: loop variable i captured by func literal