Исходники и презентации
This commit is contained in:
23
lessons/sync_primitives/incorrect_increment/main.go
Normal file
23
lessons/sync_primitives/incorrect_increment/main.go
Normal file
@ -0,0 +1,23 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"sync"
|
||||
)
|
||||
|
||||
func main() {
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1000)
|
||||
|
||||
value := 0
|
||||
for i := 0; i < 1000; i++ {
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
value++
|
||||
}()
|
||||
}
|
||||
|
||||
wg.Wait()
|
||||
|
||||
fmt.Println(value)
|
||||
}
|
||||
Reference in New Issue
Block a user