Skip to content

Commit ad5b262

Browse files
pomo16senghoo
authored andcommitted
add comments
1 parent 09ca01f commit ad5b262

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

03_singleton/singleton_test.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,13 @@ func TestParallelSingleton(t *testing.T) {
2222
instances := [parCount]*Singleton{}
2323
for i := 0; i < parCount; i++ {
2424
go func(index int) {
25+
//协程阻塞,等待channel被关闭才能继续运行
2526
<-start
2627
instances[index] = GetInstance()
2728
wg.Done()
2829
}(i)
2930
}
31+
//关闭channel,所有协程同时开始运行,实现并行(parallel)
3032
close(start)
3133
wg.Wait()
3234
for i := 1; i < parCount; i++ {

0 commit comments

Comments
 (0)