-
-
Notifications
You must be signed in to change notification settings - Fork 141
Open
Labels
Description
In Step 10, if the first goroutine is blocking while waiting for data from the pillTimer.C channel, and a second goroutine enters and stops the previous pillTimer, the first goroutine will never receive data from the pillTimer.C channel and will remain blocked until the program terminates. Although this locking mechanism in Step 10 ensures functional correctness, I wonder if this situation is still somewhat unsatisfactory.
var pillTimer *time.Timer
var pillMx sync.Mutex
func processPill() {
pillMx.Lock()
updateGhosts(ghosts, GhostStatusBlue)
if pillTimer != nil {
pillTimer.Stop()
}
pillTimer = time.NewTimer(time.Second * time.Duration(cfg.PillDurationSecs))
pillMx.Unlock()
<-pillTimer.C
pillMx.Lock()
pillTimer.Stop()
updateGhosts(ghosts, GhostStatusNormal)
pillMx.Unlock()
}
Reactions are currently unavailable