blocking.go 274 B

12345678910111213141516171819
  1. // blocking.go
  2. // throw: all goroutines are asleep - deadlock!
  3. package main
  4. import (
  5. "fmt"
  6. )
  7. func f1(in chan int) {
  8. fmt.Println(<-in)
  9. }
  10. func main() {
  11. out := make(chan int)
  12. //out := make(chan int, 1) // solution 2
  13. // go f1(out) // solution 1
  14. out <- 2
  15. go f1(out)
  16. }