mirror of
https://github.com/charlienet/go-mixed.git
synced 2025-07-18 08:32:40 +08:00
update
This commit is contained in:
31
locker/spin_locker_test.go
Normal file
31
locker/spin_locker_test.go
Normal file
@ -0,0 +1,31 @@
|
||||
package locker
|
||||
|
||||
import (
|
||||
"sync"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestSpinLock(t *testing.T) {
|
||||
l := NewSpinLocker()
|
||||
|
||||
n := 10
|
||||
c := 0
|
||||
|
||||
wg := new(sync.WaitGroup)
|
||||
wg.Add(n)
|
||||
for i := 0; i < n; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
l.Lock()
|
||||
c++
|
||||
l.Unlock()
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
l.Lock()
|
||||
t.Log(c)
|
||||
l.Unlock()
|
||||
}
|
Reference in New Issue
Block a user