Skip to content

Instantly share code, notes, and snippets.

@syossan27
Created April 29, 2018 12:41
Show Gist options
  • Select an option

  • Save syossan27/0be761ce5ab68a30b92cd3bfd254dc6f to your computer and use it in GitHub Desktop.

Select an option

Save syossan27/0be761ce5ab68a30b92cd3bfd254dc6f to your computer and use it in GitHub Desktop.
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