Goroutine Synchronization. Unbuffered vs. Buffered Channels and the Go Memory Model
Go 100 Mistakes 에 나온 8.4 경쟁 문제에 대해 완전히 이해하라 주제를 읽고 Deep dive 해봤습니다.
i := 0
ch := make(chan struct{})
go func() {
i = 1
<-ch
}()
ch <- struct{}{}
fmt.Println(i)
>>> 1
위의 코드는 항상 1이 출력된다.
i := 0
ch := make(chan struct{}, 1)
go func() {
...
tricolor-ilsan-kim.com3 min read