Could you please explain why this deadlock happens ?
package main
import (
"sync"
"fmt"
"runtime"
)
func main() {
m := sync.RWMutex{}
go func(){
m.RLock()
runtime.Gosched()
m.RLock()
m.RUnlock()
m.RUnlock()
}()
runtime.Gosched()
m.Lock()
m.Unlock()
fmt.Println("works")
}
It's non obvious to me why this deadlock always mostly happen. Could this be a quirk of the scheduler ?