initial import

This commit is contained in:
kevin
2020-07-26 17:09:05 +08:00
commit 7e3a369a8f
647 changed files with 54754 additions and 0 deletions

View File

@@ -0,0 +1,28 @@
package threading
import (
"fmt"
"runtime"
"sync"
"testing"
"zero/core/lang"
"github.com/stretchr/testify/assert"
)
func TestWorkerGroup(t *testing.T) {
m := make(map[string]lang.PlaceholderType)
var lock sync.Mutex
var wg sync.WaitGroup
wg.Add(runtime.NumCPU())
group := NewWorkerGroup(func() {
lock.Lock()
m[fmt.Sprint(RoutineId())] = lang.Placeholder
lock.Unlock()
wg.Done()
}, runtime.NumCPU())
go group.Start()
wg.Wait()
assert.Equal(t, runtime.NumCPU(), len(m))
}