mirror of
https://github.com/chai2010/advanced-go-programming-book.git
synced 2025-05-24 04:22:22 +00:00
Merge pull request #31 from barryz/fix_ch1.5_demo_compile_error
fix ch1.5 demo compile error
This commit is contained in:
commit
ce5283d057
@ -61,17 +61,21 @@ import (
|
|||||||
"sync/atomic"
|
"sync/atomic"
|
||||||
)
|
)
|
||||||
|
|
||||||
var total int64
|
var total uint64
|
||||||
|
|
||||||
func worker(wg *sync.WaitGroup) {
|
func worker(wg *sync.WaitGroup) {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
|
|
||||||
for i := 0; i <= 100; i++ {
|
var i uint64
|
||||||
|
for i = 0; i <= 100; i++ {
|
||||||
atomic.AddUint64(&total, i)
|
atomic.AddUint64(&total, i)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func main() {
|
func main() {
|
||||||
|
var wg sync.WaitGroup
|
||||||
|
wg.Add(2)
|
||||||
|
|
||||||
go worker(&wg)
|
go worker(&wg)
|
||||||
go worker(&wg)
|
go worker(&wg)
|
||||||
wg.Wait()
|
wg.Wait()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user