这是我的代码的相关摘录:
func main() {
quit := make(chan int)
readyQueue := make(chan Proc)
runQueue := make(chan Proc)
waitQueue := make(chan Proc)
procList := getInitialProcList()
fmt.Println(procList)
for _, proc := range(procList) {
switch {
case proc.Status == READY:
readyQueue <- proc
tick(quit, readyQueue, runQueue, waitQueue)
case proc.Status == RUN:
runQueue <- proc
tick(quit, readyQueue, runQueue, waitQueue)
case proc.Status == WAIT:
waitQueue <- proc
tick(quit, readyQueue, runQueue, waitQueue)
}
}
<-quit // blocks to keep main thread alive
}
func tick(quit chan int, readyQueue chan Proc, runQueue chan Proc, waitQueue chan Proc) {
select {
case p := <-readyQueue:
fmt.Println(p)
default:
fmt.Println("[tick] nothing in ready queue")
}
select {
case p := <-waitQueue:
fmt.Println(p)
default:
fmt.Println("[tick] nothing in wait queue")
}
select {
case p := <-runQueue:
fmt.Println(p)
default:
fmt.Println("[tick] nothing in run queue")
}
quit <- 0
}
我不明白为什么我得到的错误fatal error: all goroutines are asleep - deadlock!就行了readyQueue <- proc在上面的代码。
largeQ
相关分类