Skip to content

Instantly share code, notes, and snippets.

@myself659
Created April 7, 2019 14:20
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 myself659/8fd9af077add584ec7ba0a0f86bce3b5 to your computer and use it in GitHub Desktop.
Save myself659/8fd9af077add584ec7ba0a0f86bce3b5 to your computer and use it in GitHub Desktop.
sync channel example
package main
import (
"fmt"
"runtime"
)
func main() {
runtime.GOMAXPROCS(runtime.NumCPU())
synch := make(chan struct{})
for i := 0; i < 10; i++ {
print := func(s string) {
fmt.Println(s)
var ste struct{}
synch <- ste
}
fmt.Println(i, ":---")
go print("A")
<-synch
go print("B")
<-synch
go print("C")
<-synch
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment