sync.WaitGroup1 Go - Sync - 출처: https://quii.gitbook.io/learn-go-with-tests/go-fundamentals/sync - 개요 병렬 프로세스에 안전한(thread-safe) counter를 만들어본다. single-thread에서 동작하는 counter를 만들고 난 후, 여러 개의 goroutine으로 unsafe함을 확인하고 Sync를 이용해서 이를 고쳐보자. race condition을 해결하기 위한 Mutex도 사용해본다. - Counter Counter를 증가시키는 메소드와 Counter의 값을 반환하는 메소드를 만들었다고 가정한 후 test 코드를 작성해보자. func TestCounter(t *testing.T) { t.Run("incrementing the counter 3 time.. 2022. 1. 20. 이전 1 다음