Created
March 4, 2013 06:54
-
-
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
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 ( | |
"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