lock

package
v3.0.0-rc49 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 14, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Exclusive

func Exclusive(ctx context.Context, path string) (func(), error)

Exclusive takes an exclusive lock on the file at path, creating it and its directory, and returns the function releasing it. It waits for the lock until ctx is done.

It is for the short sections that must not interleave with the same section run by another process or another goroutine: the lock is held by the open file description, which every call opens anew, so it excludes the goroutines of this process as it excludes the other processes. A lock held by the process, as a fcntl lock is, would let every goroutine of the daemon in at once.

A holder dying releases the lock with its descriptors, so a crash leaves nothing to clean up and nobody to wait for.

The file is never removed. Removing a lock file on release lets a waiter that opened it before the removal and a newcomer that creates it after both hold the lock, on two files of the same name.

func Explain

func Explain(lock *flock.T, timeout time.Duration, err error) error

Explain returns err, the failure to take lock within timeout, with what holds the lock: the pid of the holder and its command line while it runs, its intent, its session and since when, as the holder wrote them in the lock file.

A lock released in the meantime, or taken by a holder that has not written who it is yet, is told as such.

func Func

func Func(lockPath string, timeout time.Duration, intent string, f func() error) error

Func call f() inside lock protection

func Lock

func Lock(lockPath string, timeout time.Duration, intent string) (func(), error)

Lock tries lock and returns release function to release lock

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL