Skip to content

Instantly share code, notes, and snippets.

@komly
Created February 14, 2016 02:42
Show Gist options
  • Select an option

  • Save komly/b017b2872245c0729148 to your computer and use it in GitHub Desktop.

Select an option

Save komly/b017b2872245c0729148 to your computer and use it in GitHub Desktop.
package main
import (
"fmt"
"sync"
)
type (
Counter struct {
count int
}
)
func boom(wg *sync.WaitGroup, num int, counter *Counter, goChan chan int) {
defer wg.Done()
for i := 0; i < 1000; i++ {
counter.count += 1
}
}
func main() {
var c Counter
var wg sync.WaitGroup
goChan := make(chan int)
wg.Add(10)
for i := 0; i < 10; i++ {
go boom(&wg, i, &c, goChan)
}
wg.Wait()
fmt.Printf("Count %d\n", c.count)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment