TryLock for Go
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Type Name Latest commit message Commit time
Failed to load latest commit information.
.travis.yml add travis CI Apr 19, 2016
LICENSE Initial commit Apr 19, 2016 fix usage in readme Apr 19, 2016
example_test.go make trylock.Mutex empty value usable Apr 19, 2016
trylock.go make trylock.Mutex empty value usable Apr 19, 2016
trylock_test.go Add test to verify sync.Mutex internal layout May 24, 2016

trylock - TryLock implementation for Go

Build Status GoDoc

trylock uses unsafe, which is sorta "unsafe", but should work until sync.Mutex will change its layout (I hope it never will).


type LockedStruct struct {
	mu trylock.Mutex

storage := &LockedStruct{}

if {
	// do something with storage
} else {
	// return busy or use some logic for unavailable storage