Skip to content

Instantly share code, notes, and snippets.

@samuell
Last active November 26, 2015 01:48
Show Gist options
  • Save samuell/03e1f4b9a20dbbef5f3c to your computer and use it in GitHub Desktop.
Save samuell/03e1f4b9a20dbbef5f3c to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"os/exec"
"sync"
)
func main() {
wg := new(sync.WaitGroup)
for i := 0; i < 355; i++ {
wg.Add(1)
go func(i int) {
fmt.Println("Starting sleep ", i, "...")
cmd := exec.Command("sleep", "3600")
_, err := cmd.Output()
if err != nil {
panic(err)
}
fmt.Println("Finishing sleep ", i, "...")
wg.Done()
}(i)
}
fmt.Println("Waiting for WaitGroup ...")
wg.Wait()
fmt.Println("WaitGroup finished!")
}
@samuell
Copy link
Author

samuell commented Nov 26, 2015

Testing it:

$ go run multiproc.go
$ ps -eLf | grep go-build | wc -l
691

... so only like 691 threads, for those 1000 go routines ...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment