-
-
Save joshkunz/0a41ae4233156b38a898 to your computer and use it in GitHub Desktop.
Go routines with manual yielding.
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" | |
import "runtime" | |
func main() { | |
runtime.GOMAXPROCS(1) | |
a := make(chan bool) | |
b := make(chan bool) | |
go func() { | |
fmt.Println("A") | |
runtime.Gosched() | |
fmt.Println("B") | |
runtime.Gosched() | |
fmt.Println("C") | |
a <- true | |
}() | |
go func() { | |
fmt.Println("D") | |
runtime.Gosched() | |
fmt.Println("E") | |
runtime.Gosched() | |
fmt.Println("F") | |
b <- true | |
}() | |
<- a | |
<- b | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment