1
0
mirror of https://github.com/charlienet/go-mixed.git synced 2025-07-17 16:12:42 +08:00
Files
go-mixed/locker/spin_locker_test.go
2024-05-28 04:23:30 +08:00

34 lines
363 B
Go

package locker_test
import (
"sync"
"testing"
"github.com/charlienet/go-mixed/locker"
)
func TestSpinLock(t *testing.T) {
l := locker.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()
}