Browse Source

Added CLI flags

master
Martins Eglitis 1 year ago
parent
commit
00bb059462
2 changed files with 11 additions and 1 deletions
  1. +1
    -0
      .gitignore
  2. +10
    -1
      main.go

+ 1
- 0
.gitignore View File

@@ -0,0 +1 @@
main

+ 10
- 1
main.go View File

@@ -1,15 +1,20 @@
package main

import (
"flag"
"fmt"
"strconv"
"strings"
"sync"
)

const concurrency = 8
var concurrency = 1

func main() {
conc := flag.Int("concurrency", 1, "Level of parallelism")
flag.Parse()
concurrency = *conc

//file, err := os.OpenFile("trace.out", os.O_WRONLY|os.O_CREATE|os.O_TRUNC, 0755)
//if err != nil {
// log.Fatal(err)
@@ -27,6 +32,7 @@ func main() {
var wg sync.WaitGroup
wg.Add(concurrency)

//Create workers.
for i := 0; i < concurrency; i++ {
go func() {
for number := range numbers {
@@ -37,14 +43,17 @@ func main() {
}()
}

//Pass numbers to the channel.
go func() {
for i := uint64(1_000_000_000); i < 1_000_000_000_0; i++ {
numbers <- i
}

//Close the channel.
close(numbers)
}()

//Wait for workers to finish.
wg.Wait()
}



Loading…
Cancel
Save