Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package main
- import (
- "fmt"
- "sync"
- "sync/atomic"
- )
- func main() {
- var wg sync.WaitGroup
- var c int64 = 0
- wg.Add(100)
- for i := 0; i < 100; i++ {
- go func() {
- var count int64
- count = c
- atomic.AddInt64(&count, 1)
- c = count
- fmt.Println(c)
- wg.Done()
- }()
- }
- wg.Wait()
- fmt.Println("End value: ", c)
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement