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:
Click to show internal directories.
Click to hide internal directories.