2018-03-18 06:02:54 +03:00
|
|
|
// Copyright 2018 The Go Authors. All rights reserved.
|
|
|
|
// Use of this source code is governed by a BSD-style
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2021-02-20 06:57:36 +03:00
|
|
|
//go:build darwin || dragonfly || freebsd || linux || netbsd || openbsd || solaris
|
2018-12-13 10:38:38 +03:00
|
|
|
// +build darwin dragonfly freebsd linux netbsd openbsd solaris
|
2018-03-19 18:24:36 +03:00
|
|
|
|
|
|
|
package unix_test
|
2018-03-18 06:02:54 +03:00
|
|
|
|
|
|
|
import (
|
|
|
|
"log"
|
|
|
|
"os"
|
2018-03-19 18:24:36 +03:00
|
|
|
|
|
|
|
"golang.org/x/sys/unix"
|
2018-03-18 06:02:54 +03:00
|
|
|
)
|
|
|
|
|
2018-08-21 06:36:55 +03:00
|
|
|
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)
|
|
|
|
}
|
|
|
|
}
|