Skip to content

Commit

Permalink
add comments
Browse files Browse the repository at this point in the history
  • Loading branch information
pomo16 authored and senghoo committed Nov 3, 2020
1 parent 09ca01f commit ad5b262
Showing 1 changed file with 2 additions and 0 deletions.
2 changes: 2 additions & 0 deletions 03_singleton/singleton_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,13 @@ func TestParallelSingleton(t *testing.T) {
instances := [parCount]*Singleton{}
for i := 0; i < parCount; i++ {
go func(index int) {
//协程阻塞,等待channel被关闭才能继续运行
<-start
instances[index] = GetInstance()
wg.Done()
}(i)
}
//关闭channel,所有协程同时开始运行,实现并行(parallel)
close(start)
wg.Wait()
for i := 1; i < parCount; i++ {
Expand Down

0 comments on commit ad5b262

Please sign in to comment.