multex

package module
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: BSD-3-Clause Imports: 1 Imported by: 4

README

Multiple mutual exclusion lock

GoDoc Go

Package mutex provides multiple mutual exclusion lock. The name is constructed by combining a common name for mutual exclusion locks, Mutex, and word multiple, which is a property of this specific implementation. Multex locking and unlocking for a single key is a few times slower then locking with sync.Mutex, but provides the ability to lock the same block of code with specific keys, allowing concurrent execution of the same code only for different keys.

Performance comparison of Multex with a single key and sync.Mutex can be done by running benchmarks in this package.

BenchmarkMultex-10      39488458                26.89 ns/op            0 B/op          0 allocs/op
BenchmarkMutex-10       86903780                13.41 ns/op            0 B/op          0 allocs/op

Installation

Run go get resenje.org/multex from command line.

Documentation

Overview

Package multex provides multiple mutual exclusion lock. The name is constructed by combining a common name for mutual exclusion locks, Mutex, and word multiple, which is a property of this specific implementation. Multex locking and unlocking for a single key is a few times slower then locking with sync.Mutex, but provides the ability to lock the same block of code with specific keys, allowing concurrent execution of the same code only for different keys.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Multex

type Multex[K comparable] struct {
	// contains filtered or unexported fields
}

Multex is a mutual exclusion lock with support for multiple keys.

func New

func New[K comparable]() (m *Multex[K])

New constructs a new Multex instance.

func (*Multex[K]) Lock

func (m *Multex[K]) Lock(key K)

Lock a specific key in Multex. This method is blocking until Unlock is called with the same key.

func (*Multex[K]) Unlock

func (m *Multex[K]) Unlock(key K)

Unlock a specific key in Multex.

Jump to

Keyboard shortcuts

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