diff --git a/.gitignore b/.gitignore index d401de0..25977dc 100644 --- a/.gitignore +++ b/.gitignore @@ -38,3 +38,4 @@ my-fnv/my-fnv my-md5/my-md5 shadir/shadir shadirconcurrent/shadirconcurrent +pinger/pinger diff --git a/pinger/main.go b/pinger/main.go new file mode 100644 index 0000000..68c9417 --- /dev/null +++ b/pinger/main.go @@ -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) + +} diff --git a/sandbox/main.go b/sandbox/main.go new file mode 100644 index 0000000..f197c3e --- /dev/null +++ b/sandbox/main.go @@ -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() +}