重写多协程问题

This commit is contained in:
JACKYMYPERSON
2025-08-31 13:10:56 +08:00
parent ee1bbb59a4
commit 42d65b3562
3 changed files with 60 additions and 2 deletions

18
main.go
View File

@@ -2,8 +2,9 @@ package main
import (
"goLearn/model"
"goLearn/reflect"
"goLearn/test"
"sync"
"time"
)
var Ch = make(chan model.Task, 3)
@@ -45,7 +46,20 @@ func main() {
//ctx := context.WithValue(context.Background(), "value", model.Task{Id: "1", Content: "1"})
//goroutine.Runtask(ctx)
reflect.FuncReflect(make([]int, 3))
//reflect.FuncReflect(make([]int, 3))
var mx sync.Mutex
ch := make(chan int, 10)
for i := 0; i < 3; i++ {
go test.GoProducer(&mx, ch)
}
for i := 0; i < 10; i++ {
go test.GoConsumer(&mx, ch)
}
time.Sleep(10 * time.Second)
defer close(ch)
}