Skip to content

Instantly share code, notes, and snippets.

@ian-kent
Created November 14, 2016 22:42
Show Gist options
  • Save ian-kent/06efa5b60d3b9f54ee07648e770a1958 to your computer and use it in GitHub Desktop.
Save ian-kent/06efa5b60d3b9f54ee07648e770a1958 to your computer and use it in GitHub Desktop.
mutex and panic
package main
import (
"fmt"
"sync"
)
func main() {
m := new(sync.Mutex)
runMe(m)
m.Lock()
m.Unlock()
}
func runMe(m *sync.Mutex) {
defer func() {
e := recover()
fmt.Println(e)
}()
m.Lock()
if true {
panic("wtf")
}
// making this `defer m.Unlock()` after `m.Lock()` fixes the deadlock
m.Unlock()
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment