Created
November 14, 2016 22:42
-
-
Save ian-kent/06efa5b60d3b9f54ee07648e770a1958 to your computer and use it in GitHub Desktop.
mutex and panic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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