/kmutex2

Sync primitive for golang. Key + Mutex = Kmutex

Primary LanguageGoGNU General Public License v3.0GPL-3.0

GoDoc

kmutex

Synchronization primitive that allows locking individual resources by unique ID.

This is not a distributed lock.

See golang.org/x/sync/singleflight if you want to reduce the number of calls to the same resource. Use kmutex if you want only one caller to use a resource at time.

Kubernetes kmutex hashes keys to a fixed set of locks, and is useful if you do not always need a separate lock for each resource. Take a look at the implementation, it is very straight forward.

GO PLAYGROUND EXAMPLE