github.com/zhiqiangxu/util@v0.0.0-20230112053021-0a7aee056cd5/deadlock/README.md (about) 1 # deadlock 2 3 This package implements a deadlock detector with easy to prove correctness, just replace `sync.Mutex` and `sync.RWMutex` with `deadlock.NewMutex()` and `deadlock.NewRWMutex()` and you're ready to go!!! 4 5 When something wrong happend, panic will happen. 6 7 Just catch the `panic` and handle it with `ParsePanicError`, like following: 8 9 ```golang 10 defer func() { 11 panicErr := recover() 12 errDeadlock, errUsage := ParsePanicError(panicErr) 13 }() 14 15 ``` 16 17 If everything went well, both `errDeadlock` and `errUsage` should be nil. 18 19 If deadlock happend, `errDeadlock` is non nil. 20 21 If usage problem happens, like the same goroutine calls `Locks` on the same `Mutex` multiple times, `errUsage` is non nil.