lock

package
v0.55.3 Latest Latest
Warning

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

Go to latest
Published: Dec 1, 2023 License: MIT Imports: 1 Imported by: 0

Documentation

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Lock

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

Lock try lock

func NewLock

func NewLock() *Lock

NewLock generate a try lock

Example
var l = NewLock()
var wg sync.WaitGroup
var counter int
for i := 0; i < 10; i++ {
	wg.Add(1)
	go func() {
		defer wg.Done()
		if l.Lock() == false {
			// log error
			println("lock failed")
			return
		}
		counter++
		println("current counter", counter)
		l.Unlock()
	}()
}
wg.Wait()
Output:

func (*Lock) Lock

func (l *Lock) Lock() bool

Lock try lock, return lock result

func (*Lock) Unlock

func (l *Lock) Unlock()

Unlock , Unlock the try lock

Jump to

Keyboard shortcuts

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