Documentation
¶
Overview ¶
--- **mutex**
Note that in the following the _scope_ closure for a deferred call of a lock is the function exit, therefore scoped lock calls lock at the defer statement and close at the end of the function not at the block *{}* level
standalone scoped mutex
https://github.com/davidwalter0/go-mutex.git
``` go get github.com/davidwalter0/go-mutex ```
Scoped execute auto unlock ¶
Call Monitor with defer for scoped lock/unlock
*Create*
```
import "github.com/davidwalter0/go-mutex" var mtx *Mutex = mutex.NewMutex()
```
*Call*
```
// Scoped call: acquire lock on entry, and release on scope
// closure
{ // enter scope lock
defer mtx.Monitor()()
// ...
// ...
// ...
} // exit scope unlock
```
*Alternative Use*
With a shared scoped set of go routines or threads an anonymous monitor created by NewMonitor can be used ¶
```
import "github.com/davidwalter0/go-mutex"
// Scoped call: acquire lock on entry, and release on scope
// closure created anonymously in the function closure
var m := mutex.NewMonitor()
{ // enter scope lock
defer m()()
// ...
// ...
// ...
} // exit scope unlock
```
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Monitor ¶
type Monitor func(...interface{}) func() // func() func()
Monitor: a deferable function scoped lock
monitor := NewMonitor() defer monitor()()
func NewMonitor ¶
func NewMonitor() Monitor
NewMonitor return a deferable preinitialized private mutex closure monitor function. defer scope: acquire lock on entry, and release on scope closure created anonymously in the function closure
Use:
monitor := NewMonitor() defer monitor()()
type Mutex ¶
Mutex local synonym for sync.Mutex for receiver methods
func (*Mutex) Guard ¶
func (mutex *Mutex) Guard() func()
Guard alias of Monitor() block scoped mutex returns function for defer call. Ex: defer mutex.Guard()()
func (*Mutex) Monitor ¶
func (mutex *Mutex) Monitor() func()
Monitor block scoped mutex block scoped mutex returns function for defer call. Ex: defer mutex.Monitor()()
func (*Mutex) MonitorTrace ¶
func (mutex *Mutex) MonitorTrace(args ...interface{}) func()
MonitorTrace block scoped mutex with depth print defer mutex.MonitorTrace()() prefer to use example from tests with defer GuardedTrace()()