Created
April 7, 2019 14:20
-
-
Save myself659/8fd9af077add584ec7ba0a0f86bce3b5 to your computer and use it in GitHub Desktop.
sync channel example
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" | |
"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