mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:33:04 +08:00
update book code
This commit is contained in:
19
eBook/exercises/chapter_14/blocking.go
Executable file
19
eBook/exercises/chapter_14/blocking.go
Executable file
@@ -0,0 +1,19 @@
|
||||
// blocking.go
|
||||
// throw: all goroutines are asleep - deadlock!
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
)
|
||||
|
||||
func f1(in chan int) {
|
||||
fmt.Println(<-in)
|
||||
}
|
||||
|
||||
func main() {
|
||||
out := make(chan int)
|
||||
//out := make(chan int, 1) // solution 2
|
||||
// go f1(out) // solution 1
|
||||
out <- 2
|
||||
go f1(out)
|
||||
}
|
Reference in New Issue
Block a user