我对Golang很新.我为练习编写了以下代码,并遇到了死锁的运行时错误消息:
package main
import (
"fmt"
)
func system(WORKERS int) {
fromW := make(chan bool)
toW := make(chan bool)
for i := 0; i != WORKERS; i++ {
go worker(toW, fromW)
}
coordinator(WORKERS, fromW, toW)
}
func coordinator(WORKERS int, in, out chan bool) {
result := true
for i := 0; i != WORKERS; i++ {
result = result && <-in
}
for i := 0; i != WORKERS; i++ {
out <- result
}
fmt.Println("%t", result)
}
func worker(in, …Run Code Online (Sandbox Code Playgroud)