parent
0c3b8807dd
commit
3c5bfd8e6b
@ -0,0 +1,23 @@
|
|||||||
|
package goConcurrency
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"testing"
|
||||||
|
)
|
||||||
|
|
||||||
|
func TestWalkDir(t *testing.T) {
|
||||||
|
dirs := []string{
|
||||||
|
//`D:\apps\mashibing`,
|
||||||
|
//`D:\apps\kubernetes`,
|
||||||
|
}
|
||||||
|
fmt.Println(WalkDir(dirs...))
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestQuickSortConcurrency(t *testing.T) {
|
||||||
|
//randArr := []int{
|
||||||
|
// 19, 21, 0, -8, 11, 12, 19, 7, 25, 33, 2, 5,
|
||||||
|
//}
|
||||||
|
randArr := GenerateRandArr(10000)
|
||||||
|
sortArr := QuickSortConcurrency(randArr)
|
||||||
|
fmt.Println(sortArr)
|
||||||
|
}
|
@ -1,3 +1,5 @@
|
|||||||
module goConcurrency
|
module goConcurrency
|
||||||
|
|
||||||
go 1.19
|
go 1.19
|
||||||
|
|
||||||
|
require github.com/panjf2000/ants/v2 v2.7.1 // indirect
|
||||||
|
@ -0,0 +1,15 @@
|
|||||||
|
github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||||
|
github.com/panjf2000/ants/v2 v2.7.1 h1:qBy5lfSdbxvrR0yUnZfaEDjf0FlCw4ufsbcsxmE7r+M=
|
||||||
|
github.com/panjf2000/ants/v2 v2.7.1/go.mod h1:KIBmYG9QQX5U2qzFP/yQJaq/nSb6rahS9iEHkrCMgM8=
|
||||||
|
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
|
github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=
|
||||||
|
github.com/stretchr/objx v0.4.0/go.mod h1:YvHI0jy2hoMjB+UWwv71VJQ9isScKT/TqJzVSSt89Yw=
|
||||||
|
github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpEOglKo=
|
||||||
|
github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
|
||||||
|
github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU=
|
||||||
|
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
|
||||||
|
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
|
||||||
|
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||||
|
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||||
|
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
@ -0,0 +1,27 @@
|
|||||||
|
package goConcurrency
|
||||||
|
|
||||||
|
import "testing"
|
||||||
|
|
||||||
|
func TestGoroutineGo(t *testing.T) {
|
||||||
|
GoroutineGo()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoroutineWG(t *testing.T) {
|
||||||
|
GoroutineWG()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoroutineNum(t *testing.T) {
|
||||||
|
GoroutineNum()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoroutineAnts(t *testing.T) {
|
||||||
|
GoroutineAnts()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoroutineRandom(t *testing.T) {
|
||||||
|
GoroutineRandom()
|
||||||
|
}
|
||||||
|
|
||||||
|
func TestGoroutineSched(t *testing.T) {
|
||||||
|
GoroutineSched()
|
||||||
|
}
|
@ -0,0 +1,24 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"sync"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
ch := make(chan int, 10)
|
||||||
|
wg := sync.WaitGroup{}
|
||||||
|
wg.Add(1)
|
||||||
|
go func() {
|
||||||
|
defer wg.Done()
|
||||||
|
for i := 0; i < 10; i++ {
|
||||||
|
ch <- i
|
||||||
|
fmt.Println(i)
|
||||||
|
}
|
||||||
|
close(ch)
|
||||||
|
}()
|
||||||
|
wg.Wait()
|
||||||
|
for n := range ch {
|
||||||
|
fmt.Println("Read:", n)
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in new issue