Last active
August 29, 2024 12:52
-
-
Save Leowbattle/84fcefb41c10783bbfbd3b8524f9b15a to your computer and use it in GitHub Desktop.
Shader derivatives in Go
This file contains hidden or 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
| // 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