Skip to content

Instantly share code, notes, and snippets.

@samuell
Created May 30, 2016 13:53
Show Gist options
  • Save samuell/5d8de4e184e6055248cc23c20d872166 to your computer and use it in GitHub Desktop.
Save samuell/5d8de4e184e6055248cc23c20d872166 to your computer and use it in GitHub Desktop.
package main
import (
"bytes"
"fmt"
"os/exec"
"sync"
)
func main() {
wg := new(sync.WaitGroup)
for i := 0; i < 5000; i++ {
wg.Add(1)
go func(i int) {
fmt.Println("Starting sleep ", i, "...")
cmd := exec.Command("sleep", "3600")
cmdOut := &bytes.Buffer{}
cmd.Stdout = cmdOut
err := cmd.Start()
if err != nil {
panic(err)
}
cmd.Wait()
fmt.Println("Finishing sleep ", i, "...")
wg.Done()
}(i)
}
fmt.Println("Waiting for WaitGroup ...")
wg.Wait()
fmt.Println("WaitGroup finished!")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment