Skip to content

Instantly share code, notes, and snippets.

@maxsei
Created August 21, 2024 18:56
Show Gist options
  • Save maxsei/cd17f57e953b6ebe8f8577bc33dd50c1 to your computer and use it in GitHub Desktop.
Save maxsei/cd17f57e953b6ebe8f8577bc33dd50c1 to your computer and use it in GitHub Desktop.
debug mutex lol
package main
import (
"fmt"
"runtime"
"sync"
)
func NewDebugMutex() sync.Locker {
return &debugMutex{}
}
type debugMutex struct {
sync.Mutex
}
func (m *debugMutex) Lock() {
m.Mutex.Lock()
_, file, line, ok := runtime.Caller(1)
if !ok {
panic("Could not get caller information")
}
println(fmt.Sprintf("Mutex Lock %p: %s:%d", m, file, line))
}
func (m *debugMutex) Unlock() {
_, file, line, ok := runtime.Caller(1)
if !ok {
panic("Could not get caller information")
}
println(fmt.Sprintf("Mutex Unlock %p: %s:%d", m, file, line))
m.Mutex.Unlock()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment