Skip to content

Commit

Permalink
limit parallelism to the number of CPUs
Browse files Browse the repository at this point in the history
  • Loading branch information
CAFxX committed May 20, 2023
1 parent 6e0f09e commit b635e03
Showing 1 changed file with 3 additions and 0 deletions.
3 changes: 3 additions & 0 deletions main.go
Expand Up @@ -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)
Expand Down

0 comments on commit b635e03

Please sign in to comment.