Created
December 4, 2015 13:54
-
-
Save perillo/d397708cf9bada8a24d5 to your computer and use it in GitHub Desktop.
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" | |
"time" | |
"unsafe" | |
) | |
func producer(ch chan<- int) { | |
ch <- 777 | |
} | |
func producer_bad(ch chan<- int) { | |
newch := (*<-chan int)(unsafe.Pointer(&ch)) | |
consumer(*newch) | |
} | |
func consumer(ch <-chan int) { | |
fmt.Printf("consumed %d\n", <-ch) | |
} | |
func main() { | |
ch := make(chan int) | |
go producer(ch) | |
go producer_bad(ch) | |
time.Sleep(1 * time.Second) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment