go-multilocker

module
v0.0.0-...-8cc59df Latest Latest
Warning

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

Go to latest
Published: Nov 16, 2020 License: MIT

README

multilocker

Documentation

Install

go get github.com/TheCount/go-multilocker/multilocker

Usage

For the detailed API, see the Documentation.

Example:

var mtx1, mtx2 sync.Mutex

// goroutine 1
go func() {
  ml := multilocker.New(&mtx1, &mtx2)
  ml.Lock()
  ml.Unlock()
}()

// goroutine 2
go func() {
  ml := multilocker.New(&mtx2, &mtx1)
  ml.Lock()
  ml.Unlock()
}()

This example would be prone to deadlocks if goroutine 1 locked first mtx1, then mtx2, while goroutine 2 attempted to lock mtx2 first, and then mtx1. The use of a multilocker makes locking and unlocking atomic and deadlock-free in this example.

Directories

Path Synopsis
Package multilocker allows you to atomically lock multiple sync.Lockers at once while avoiding deadlocks.
Package multilocker allows you to atomically lock multiple sync.Lockers at once while avoiding deadlocks.

Jump to

Keyboard shortcuts

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