Исходники и презентации
This commit is contained in:
34
lessons/sync_primitives/mutex_with_common_values/main.go
Normal file
34
lessons/sync_primitives/mutex_with_common_values/main.go
Normal file
@ -0,0 +1,34 @@
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
// go run -race main.go
|
||||
|
||||
type Data struct {
|
||||
X int
|
||||
Y int
|
||||
}
|
||||
|
||||
func main() {
|
||||
var data Data
|
||||
values := make([]int, 2)
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(2)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
data.X = 5
|
||||
values[0] = 5
|
||||
}()
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
|
||||
data.Y = 10
|
||||
values[1] = 10
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
}
|
||||
Reference in New Issue
Block a user