-
-
Save volodimyr/efae62acc0644e6d0a3fb0d559a68fca to your computer and use it in GitHub Desktop.
Deadlock concurrency in golang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import "fmt" | |
var ( | |
first chan string | |
second chan string | |
) | |
func main() { | |
go forever() | |
second <- "From main" | |
} | |
func forever() { | |
for { | |
select { | |
case f := <-first: | |
fmt.Println(f) | |
case s := <-second: | |
block(s) | |
} | |
} | |
} | |
func block(str string) { | |
first <- "From block function " + str | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment