mutex

package module
v0.0.0-...-6b72e02 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2018 License: Apache-2.0 Imports: 2 Imported by: 4

README


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

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

type Mutex sync.Mutex

Mutex local synonym for sync.Mutex for receiver methods

func NewMutex

func NewMutex() *Mutex

NewMutex return a mutex pointer

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) Lock

func (mutex *Mutex) Lock()

Lock the mutex

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()()

func (*Mutex) Unlock

func (mutex *Mutex) Unlock()

Unlock the mutex

Jump to

Keyboard shortcuts

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