Skip to content

Instantly share code, notes, and snippets.

@yifan-gu
Created December 18, 2015 18:38
Show Gist options
  • Save yifan-gu/50bfb8bffd839c219e7b to your computer and use it in GitHub Desktop.
Save yifan-gu/50bfb8bffd839c219e7b to your computer and use it in GitHub Desktop.
lock
package main
import (
"fmt"
"os"
"github.com/coreos/rkt/pkg/lock"
)
func lockAndPrint() {
lock.ExclusiveLock("/tmp/hello", lock.Dir)
fmt.Println("hello")
}
func main() {
os.Mkdir("/tmp/hello", 0777)
defer os.RemoveAll("/tmp/hello")
lockAndPrint()
lockAndPrint()
}
@yifan-gu
Copy link
Author

$ go run lockandprint.go 
hello

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment