Advertisement
milton19

deadlock.go

May 30th, 2018
35
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Go 0.69 KB | None | 0 0
  1. package main
  2.  
  3. type end struct{}
  4.  
  5. // !int . ?string . end
  6. func party1(intChannel chan int, stringChannel chan string, endChannel chan end) {
  7.     //!int
  8.     intChannel <- 42
  9.     // ?string
  10.     <-stringChannel
  11.     // end
  12.     endChannel <- end{}
  13.  
  14. }
  15.  
  16. // !string . ?int . end
  17. func party2(intChannel chan int, stringChannel chan string, endChannel chan end) {
  18.     //!string
  19.     stringChannel <- "Hello World"
  20.     // ?int
  21.     <-intChannel
  22.     //end
  23.     endChannel <- end{}
  24. }
  25.  
  26. func main() {
  27.     intChannel := make(chan int)
  28.     stringChannel := make(chan string)
  29.     endChannel := make(chan end)
  30.     go party1(intChannel, stringChannel, endChannel)
  31.     go party2(intChannel, stringChannel, endChannel)
  32.     <-endChannel
  33.     <-endChannel
  34. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement