Created
February 14, 2016 02:42
-
-
Save komly/b017b2872245c0729148 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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