Created
April 29, 2018 12:41
-
-
Save syossan27/0be761ce5ab68a30b92cd3bfd254dc6f 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 ( | |
| "sync" | |
| "fmt" | |
| ) | |
| var ( | |
| balance int32 = 100 | |
| wg = sync.WaitGroup{} | |
| ) | |
| func main() { | |
| // expect: balance = 55 | |
| var i int32 | |
| for i = 0; i < 10; i++ { | |
| wg.Add(1) | |
| go withdraw(i) | |
| } | |
| wg.Wait() | |
| fmt.Println(balance) | |
| } | |
| func withdraw(amount int32) { | |
| balance = balance - amount | |
| wg.Done() | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment