Skip to content

Instantly share code, notes, and snippets.

@joshkunz
Created September 4, 2015 02:36
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joshkunz/0a41ae4233156b38a898 to your computer and use it in GitHub Desktop.
Save joshkunz/0a41ae4233156b38a898 to your computer and use it in GitHub Desktop.
Go routines with manual yielding.
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