I am trying to figure out what is that is making my program hanging, most of my locks shouldn't be held for more than 200 ms. (actually much less!)
I want to create two new functions (Lock()
and Unlock()
) so that Lock will have a timer that will panic if Lock has been held for more than 200 ms.
This is my current attempt, but it doesn't work, any hint?
type ShardKV struct {
lockChan chan bool
}
func (kv *App) lock(reason string) {
kv.mu.Lock()
f := func () {
fmt.Println("PANIC: ms passed")
select {
case <- kv.lockChan:
//
default:
panic("PANIC: " + reason)
}
}
time.AfterFunc(time.Second * 10, f)
}
func (kv *App) unlock(reason string) {
kv.lockChan <- true
kv.mu.Unlock()
}