mirror of
https://github.com/golang/sys.git
synced 2026-02-08 11:46:04 +03:00
unix: add example for Flock
The method signature does not explain much about how to use the function, and which arguments to invoke it with, so an example would be helpful. Change-Id: I95747567b2cafe70da1e04939c39f6b507f12684 Reviewed-on: https://go-review.googlesource.com/130317 Reviewed-by: Brad Fitzpatrick <bradfitz@golang.org> Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org>
This commit is contained in:
committed by
Brad Fitzpatrick
parent
1a700e749c
commit
4ea2f632f6
@@ -17,3 +17,14 @@ func ExampleExec() {
|
||||
err := unix.Exec("/bin/ls", []string{"ls", "-al"}, os.Environ())
|
||||
log.Fatal(err)
|
||||
}
|
||||
|
||||
func ExampleFlock() {
|
||||
f, _ := os.Create("example.lock")
|
||||
if err := unix.Flock(int(f.Fd()), unix.LOCK_EX); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
// Do work here that requires the lock. When finished, release the lock:
|
||||
if err := unix.Flock(int(f.Fd()), unix.LOCK_UN); err != nil {
|
||||
log.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user