You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
420 B
36 lines
420 B
6 years ago
|
package utils
|
||
|
|
||
|
import (
|
||
|
"sync"
|
||
|
"testing"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
6 years ago
|
var NumThreads = 20
|
||
6 years ago
|
|
||
|
func TestSingleton(t *testing.T) {
|
||
|
var wg sync.WaitGroup
|
||
|
|
||
|
for i := 0; i < NumThreads; i++ {
|
||
|
wg.Add(1)
|
||
|
go func() {
|
||
|
defer wg.Done()
|
||
|
time.Sleep(time.Millisecond)
|
||
|
|
||
|
}()
|
||
|
}
|
||
|
wg.Wait()
|
||
|
|
||
|
n := 100
|
||
|
for i := 0; i < NumThreads; i++ {
|
||
|
wg.Add(1)
|
||
|
go func() {
|
||
|
defer wg.Done()
|
||
|
n++
|
||
|
time.Sleep(time.Millisecond)
|
||
|
}()
|
||
|
}
|
||
|
|
||
|
wg.Wait()
|
||
|
}
|