我正面临一个烦人的问题。当我尝试使用wg.Add()来同步我的例程时,会引发死锁错误。 package main
import (
"fmt"
"sync"
)
func hello(ch chan int, num int, wg *sync.WaitGroup) {
for {
i := <-ch
if i == num {
我有一个例子代码之前sync.WaitGroup结束够程(你可以找到它的Go Playground): package main
import (
"fmt"
"sync"
"time"
)
func main() {
messages := make(chan int)
var wg sync.WaitGroup
var res
我从https://blog.golang.org/pipelines看一下例子: func main() {
in := gen(2, 3)
// Distribute the sq work across two goroutines that both read from in.
c1 := sq(in)
// When does this lin