Skip to content

Instantly share code, notes, and snippets.

@perillo
Created December 4, 2015 13:54
Show Gist options
  • Save perillo/d397708cf9bada8a24d5 to your computer and use it in GitHub Desktop.
Save perillo/d397708cf9bada8a24d5 to your computer and use it in GitHub Desktop.
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