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