Concurrency tests

This commit is contained in:
Meutel 2017-07-08 14:54:39 +02:00
parent 5df5aa394a
commit bb1ac4fe40
3 changed files with 47 additions and 0 deletions

1
.gitignore vendored
View File

@ -38,3 +38,4 @@ my-fnv/my-fnv
my-md5/my-md5
shadir/shadir
shadirconcurrent/shadirconcurrent
pinger/pinger

29
pinger/main.go Normal file
View File

@ -0,0 +1,29 @@
package main
import "fmt"
import "time"
func pinger(c chan string) {
c <- "ping"
}
func ponger(c1 chan string, c2 chan string) {
<-c1
c2 <- "pong"
}
func printer(c chan string) {
msg := <-c
fmt.Println(msg)
time.Sleep(time.Second)
}
func main() {
pingChan, pongChan := make(chan string), make(chan string)
go pinger(pingChan)
go ponger(pingChan, pongChan)
go printer(pongChan)
var input string
fmt.Scanln(&input)
}

17
sandbox/main.go Normal file
View File

@ -0,0 +1,17 @@
package main
import "fmt"
import "sync"
var wg sync.WaitGroup
func main() {
for i := 0; i < 5; i++ {
go func() {
defer wg.Done()
wg.Add(1)
fmt.Println("Hello World")
}()
}
wg.Wait()
}