Skip to content

Commit cc5e1ed

Browse files
committed
Update
1 parent ced09ff commit cc5e1ed

File tree

2 files changed

+16
-36
lines changed

2 files changed

+16
-36
lines changed

examples/singleapp/count_down_latch/countdownlatch.go

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -69,18 +69,3 @@ func (me *CountdownLatch) CurrentCount() int {
6969

7070
return int(me.count.Load())
7171
}
72-
73-
// Reset は、カウントを指定された値にリセットします.
74-
// リセットすることになるため、強制的にカウント満了したことになり、待機している非同期処理が存在する場合は解除されます.
75-
func (me *CountdownLatch) Reset(count int) {
76-
if count < 0 {
77-
panic("リセットカウントは0以上である必要があります")
78-
}
79-
80-
me.mutex.Lock()
81-
defer me.mutex.Unlock()
82-
83-
me.cond.Broadcast()
84-
85-
me.count.Store(int32(count))
86-
}

examples/singleapp/count_down_latch/main.go

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -70,30 +70,25 @@ func proc(_ context.Context) error {
7070
wg sync.WaitGroup
7171
)
7272

73-
for range 2 {
74-
latch.Reset(latchCount)
75-
76-
for i := range 5 {
77-
wg.Add(1)
78-
go func(i int) {
79-
defer wg.Done()
80-
81-
log.Printf("[%2d] 待機開始", i)
82-
latch.Wait()
83-
log.Printf("[%2d] 待機解除", i)
84-
}(i)
85-
}
73+
for i := range 5 {
74+
wg.Add(1)
75+
go func(i int) {
76+
defer wg.Done()
77+
78+
log.Printf("[%2d] 待機開始", i)
79+
latch.Wait()
80+
log.Printf("[%2d] 待機解除", i)
81+
}(i)
82+
}
8683

87-
for range 3 {
88-
<-time.After(time.Second)
84+
for range 3 {
85+
<-time.After(time.Second)
8986

90-
log.Printf("現在のカウント: %d\n", latch.CurrentCount())
91-
latch.Signal()
92-
}
93-
94-
wg.Wait()
95-
log.Println("-------------------------------------")
87+
log.Printf("現在のカウント: %d\n", latch.CurrentCount())
88+
latch.Signal()
9689
}
9790

91+
wg.Wait()
92+
9893
return nil
9994
}

0 commit comments

Comments
 (0)