Skip to content

Instantly share code, notes, and snippets.

@Leowbattle
Last active August 29, 2024 12:52
Show Gist options
  • Save Leowbattle/84fcefb41c10783bbfbd3b8524f9b15a to your computer and use it in GitHub Desktop.
Save Leowbattle/84fcefb41c10783bbfbd3b8524f9b15a to your computer and use it in GitHub Desktop.
Shader derivatives in Go
// You can edit this code!
// Click here and start typing.
package main
import "fmt"
func shader(id int, c chan int) {
x := id
c <- x
dx := <-c
fmt.Printf("Thread %d. x = %d. dx = %d\n", id, x, dx)
// Return value
c <- 0
}
func main() {
c1 := make(chan int)
c2 := make(chan int)
go shader(1, c1)
go shader(20, c2)
x1 := <-c1
x2 := <-c2
dx := x2 - x1
c1 <- dx
c2 <- dx
ret1 := <-c1
ret2 := <-c2
fmt.Printf("1 returns %d\n", ret1)
fmt.Printf("2 returns %d\n", ret2)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment