flock

package
v0.67.0 Latest Latest
Warning

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

Go to latest
Published: Nov 19, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package flock holds advisory file locks, which the kernel drops with the holder's process, so a crashed holder never strands one.

Index

Constants

This section is empty.

Variables

View Source
var ErrHeld = errors.New("lock held")

ErrHeld is a lock another holder has.

Functions

func Exclusive

func Exclusive(f *os.File) error

Exclusive locks f without waiting.

func Probe

func Probe(path string) (string, bool)

Probe reports the holder line of path's lease, false when nobody holds it. It takes a shared lock for an instant, which Acquire's retries absorb.

func Shared

func Shared(f *os.File) error

Shared takes f's shared lock without waiting.

func Unlock

func Unlock(f *os.File) error

Unlock drops whichever lock f holds.

func Wait

func Wait(path string, wait time.Duration) (func(), error)

Wait takes path's exclusive lock, retrying until wait runs out; the returned func releases it.

Types

type HeldError

type HeldError struct {
	Path   string
	Holder string
}

A HeldError is a lease another holder has; Holder is the line it wrote.

func (HeldError) Error

func (e HeldError) Error() string

type Lease

type Lease struct {
	// contains filtered or unexported fields
}

A Lease is a held lock file, released by Release or by the process ending. Lock files are never deleted: unlinking a held one lets a second process lock a fresh inode under the same name.

func Acquire

func Acquire(path, holder string) (*Lease, error)

Acquire takes path's lease without waiting on a holder, writing holder into the file for Probe to read; a held one is a HeldError naming it.

func (*Lease) Release

func (l *Lease) Release()

Release drops the lease; nil and a second call are fine.

Jump to

Keyboard shortcuts

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