MCPcopy
hub / github.com/ChineseSubFinder/ChineseSubFinder / ExampleNewLock

Function ExampleNewLock

pkg/lock/example_test.go:5–24  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

3import "sync"
4
5func ExampleNewLock() {
6 var l = NewLock()
7 var wg sync.WaitGroup
8 var counter int
9 for i := 0; i < 10; i++ {
10 wg.Add(1)
11 go func() {
12 defer wg.Done()
13 if l.Lock() == false {
14 // log error
15 println("lock failed")
16 return
17 }
18 counter++
19 println("current counter", counter)
20 l.Unlock()
21 }()
22 }
23 wg.Wait()
24}

Callers

nothing calls this directly

Calls 5

NewLockFunction · 0.85
LockMethod · 0.80
UnlockMethod · 0.80
AddMethod · 0.45
WaitMethod · 0.45

Tested by

no test coverage detected