daheige / trylock-1

TryLock for Go

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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).

Usage

type LockedStruct struct {
	mu trylock.Mutex
}

storage := &LockedStruct{}

if storage.mu.TryLock() {
	// do something with storage
} else {
	// return busy or use some logic for unavailable storage
}

About

TryLock for Go

License:MIT License


Languages

Language:Go 100.0%