Skip to content

Instantly share code, notes, and snippets.

@arindamroynitw
Created September 15, 2019 17:56
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arindamroynitw/5e2b5dacf2bf48b75fbe8c0b46e0d625 to your computer and use it in GitHub Desktop.
Save arindamroynitw/5e2b5dacf2bf48b75fbe8c0b46e0d625 to your computer and use it in GitHub Desktop.
Parallel Execution
package main
import (
"fmt"
"math/rand"
"sync"
"time"
)
func main() {
list := []string{"a", "b", "c", "d", "e", "f", "g", "h"}
var wg sync.WaitGroup
wg.Add(len(list))
for i := 0; i < len(list); i++ {
go func(val string) {
defer wg.Done()
d := time.Duration(rand.Intn(10)) * time.Microsecond
time.Sleep(d)
fmt.Printf("Current value is : %s \n", val)
}(list[i])
}
wg.Wait()
fmt.Println("Program finished executing")
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment