muSupervisor

package module
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jul 6, 2020 License: MIT Imports: 8 Imported by: 0

README

Mutex Supervisor

Have you ever been stuck on a mutex deadlock without knowing what caused it? Well, I have.

This simple tool can wrap any sync.Mutex or sync.RWmutex with the same behavior, but it will verbosely log if any lock request doesn't get satisfied in a specified amount of time. The output log will contain stack trace of the timed-out request as well as the stack trace of any other active or pending RLock request on that mutex.

How to use

If you are just using sync.Mutex and sync.RWMutex, you can import this module instead of the sync module (aliasing it):

import sync "github.com/EdoaLive/muSupervisor"

If you prefer to not replace the sync module or use both differently, you can use it separately:

import "github.com/EdoaLive/muSupervisor"

var (
	mutex1 muSupervisor.Mutex
	mutex2 muSupervisor.RWMutex
)

Please, please, please. Use this tool only in debugging and testing. Not in production.

TODO

  • Write a more exhaustive test (current is merely an example)
  • Fix a condition in which the stack trace is not saved
  • Improve comments and documentation

Documentation

Index

Constants

View Source
const (
	LOCK opType = iota
	UNLOCK
	RLOCK
	RUNLOCK
)
View Source
const (
	PENDING opState = iota
	ACTIVE
	DONE
)

Variables

View Source
var Opts = struct {
	// Waiting for a lock for longer than DeadlockTimeout is considered a deadlock.
	DeadlockTimeout time.Duration
	// The frequency at which timeout checks are performed
	CheckFrequency time.Duration
	// After this time already satisfied requests will be cleaned up
	CleanTimeout time.Duration
}{
	DeadlockTimeout: time.Second * 5,
	CheckFrequency:  time.Second * 1,
	CleanTimeout:    time.Second * 20,
}

Functions

This section is empty.

Types

type Mutex

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

func (*Mutex) Lock

func (m *Mutex) Lock()

func (*Mutex) Unlock

func (m *Mutex) Unlock()

type RWMutex

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

func (*RWMutex) Lock

func (m *RWMutex) Lock()

func (*RWMutex) RLock

func (m *RWMutex) RLock()

func (*RWMutex) RUnlock

func (m *RWMutex) RUnlock()

func (*RWMutex) Unlock

func (m *RWMutex) Unlock()

Jump to

Keyboard shortcuts

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