From 4ea2f632f6e912459fe60b26b1749377f0d889d5 Mon Sep 17 00:00:00 2001 From: Kevin Burke Date: Mon, 20 Aug 2018 20:36:55 -0700 Subject: [PATCH] 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 Run-TryBot: Brad Fitzpatrick TryBot-Result: Gobot Gobot --- unix/example_test.go | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/unix/example_test.go b/unix/example_test.go index 10619afd..ccdcf731 100644 --- a/unix/example_test.go +++ b/unix/example_test.go @@ -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) + } +}