Created
March 30, 2017 11:09
-
-
Save alextanhongpin/f8c302f5d1ac3a77ae3278f9b4aa4644 to your computer and use it in GitHub Desktop.
sample-mutex
This file contains 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" | |
) | |
func main() { | |
wg := &sync.WaitGroup{} | |
wg.Add(100) | |
s := make([]int, 0) | |
for i := 0; i < 100; i++ { | |
go update(&s, wg) | |
} | |
wg.Wait() | |
fmt.Println(len(s)) | |
} | |
func update(s *[]int, wg *sync.WaitGroup) { | |
*s = append(*s, 1) | |
wg.Done() | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment