GitBucket
4.23.0
Toggle navigation
Sign in
Files
Branches
1
Releases
Issues
Pull requests
Labels
Priorities
Milestones
Wiki
Forks
sample-golang
/
01_hello
Browse code
add sample
master
1 parent
cfd59e7
commit
be7f3f99c920b072aba030843a291d65de8c74f6
yhornisse
authored
on 9 Oct 2021
Patch
Showing
2 changed files
goroutine/README.md
goroutine/parallel.go
Ignore Space
Show notes
View
goroutine/README.md
## MEMO - 最初に呼び出されるgoroutineはmain goroutine - `make(chan string)` でバッファなし、 `make(chan string, 10)`のように書けばバッファあり バッファがいっぱい場合は受信されて空きができるまで待たされる。
## MEMO - 最初に呼び出されるgoroutineはmain goroutine
Ignore Space
Show notes
View
goroutine/parallel.go
0 → 100644
package main import ( "fmt" ) func main() { ng() // 2, 2, 2 ok() // 0, 1, 2 } func ng() { ary := [3]int{1, 2, 3} done := make(chan bool) for i := range ary { go func() { fmt.Println(i) // NG done <- true }() } for i := 0; i < 3; i++ { <- done } } func ok() { ary := [3]int{1, 2, 3} done := make(chan bool) for i := range ary { go func(i int) { fmt.Println(i) done <- true }(i) } for i := 0; i < 3; i++ { <- done } }
Show line notes below