From b635e037ff2f5e2e35da093784770a6dea337bff Mon Sep 17 00:00:00 2001 From: Carlo Alberto Ferraris Date: Sat, 20 May 2023 01:27:55 +0000 Subject: [PATCH] limit parallelism to the number of CPUs --- main.go | 3 +++ 1 file changed, 3 insertions(+) diff --git a/main.go b/main.go index dd47ee2..9588ded 100644 --- a/main.go +++ b/main.go @@ -117,9 +117,12 @@ func main() { } eg, ctx := errgroup.WithContext(context.Background()) + sema := make(chan struct{}, runtime.NumCPU()) for _, v := range []string{"v1", "v2", "v3", "v4"} { v := v eg.Go(func() error { + sema <- struct{}{} + defer func() { <-sema }() cmd := exec.CommandContext(ctx, "go") cmd.Args = append([]string{"go", "build", "-o", filepath.Join(tmpdir, "launcher", "mgo."+v)}, args...) cmd.Env = append(os.Environ(), "GOAMD64="+v)