Skip to content

Instantly share code, notes, and snippets.

@bradclawsie
Created March 4, 2013 06:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bradclawsie/5080501 to your computer and use it in GitHub Desktop.
Save bradclawsie/5080501 to your computer and use it in GitHub Desktop.
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