This code (a single threaded program) will never work:
func TestDoubleLockPanics(t *testing.T) {
var mu sync.Mutex
mu.Lock()
mu.Lock()
}
However, when I run this test, there's no panic. The race detector does not print out a data race. go vet
does not complain, there's no log message, it just blocks forever.
(The actual real-life code I care about is, obviously, not this simple - I've just boiled it down to the essence.)
Is there any way to get Go to tell me, loudly, when a thread that holds a lock attempts to re-acquire the same lock?