werfen: alle goroutines schlafen - Deadlock

Gegeben das folgende einfache Programm Gehen

package main

import (
    "fmt"
)

func total(ch chan int) {
    res := 0
    for iter := range ch {
        res += iter
    }
    ch <- res
}

func main() {
    ch := make(chan int)
    go total(ch)
    ch <- 1
    ch <- 2
    ch <- 3
    fmt.Println("Total is ", <-ch)
}

Frage ich mich, ob jemand kann mich aufklären, warum bekomme ich

throw: all goroutines are asleep - deadlock!

danke

InformationsquelleAutor der Frage adk | 2012-09-13

Schreibe einen Kommentar