Skip to content

Instantly share code, notes, and snippets.

@minhphong306
Last active April 19, 2020 14:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minhphong306/4eb680e5d4271a301870acd7e2f5f265 to your computer and use it in GitHub Desktop.
Save minhphong306/4eb680e5d4271a301870acd7e2f5f265 to your computer and use it in GitHub Desktop.
race_condition.go
package main
import (
"fmt"
"sync"
)
var x int64 = 0
func addOne(wg *sync.WaitGroup) {
x = x + 1
wg.Done()
}
func main() {
var w sync.WaitGroup
for i := 0; i < 1000; i++ {
w.Add(1)
go addOne(&w)
}
w.Wait()
fmt.Println("Giá trị của x là: ", x)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment