```
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
var wg sync.WaitGroup
//计算一个64位随机数的各位的和
func randNumber(x int64) int64 {
var sum int64 = 0
for x > 0 {
a := x % 10
x = x / 10
sum += a
}
return sum
}
func main() {
wg.Add(25)
var jobChan = make(chan int64, 10)
var resultChan = make(chan int64, 10)
go func(jobChan chan<- int64, ) {
defer wg.Done()
for i:=0;i<1000;i++{
rand.Seed(time.Now().UnixNano())
jobChan <- rand.Int63n(100)
}
}(jobChan)
for i:=0;i<24;i++{
go func(jobChan <-chan int64, resultChan chan<- int64, ) {
defer wg.Done()
for num:= range jobChan{
resultChan <- randNumber(num)
}
}(jobChan, resultChan)
}
for i:= range resultChan{
fmt.Println(i)
}
wg.Wait()
}
```
发生错误:fatal error: all goroutines are asleep - deadlock!
请问为什么会发生死锁的问题
有疑问加站长微信联系(非本文作者)