Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
a minimal program that obtains a golock lock. compile to "testlock" with go build testlock.go
package main
import (
"os"
"fmt"
"time"
"github.com/bradclawsie/golock"
)
func main() {
ln := lock.GetenvLockName()
if ln == "" {
fmt.Printf("no lock name\n")
os.Exit(1)
}
lck,lck_err := lock.New(ln)
if lck_err != nil {
fmt.Printf("cannot lock:%s\n",lck_err.Error())
os.Exit(1)
}
time.Sleep(time.Duration(10) * time.Second)
_ = lck.Release()
os.Exit(0)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.