Concurrency tests
This commit is contained in:
parent
5df5aa394a
commit
bb1ac4fe40
1
.gitignore
vendored
1
.gitignore
vendored
@ -38,3 +38,4 @@ my-fnv/my-fnv
|
||||
my-md5/my-md5
|
||||
shadir/shadir
|
||||
shadirconcurrent/shadirconcurrent
|
||||
pinger/pinger
|
||||
|
29
pinger/main.go
Normal file
29
pinger/main.go
Normal 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
17
sandbox/main.go
Normal 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()
|
||||
}
|
Loading…
Reference in New Issue
Block a user