Исходники и презентации
This commit is contained in:
20
lessons/sync_primitives/lockable_struct/main.go
Normal file
20
lessons/sync_primitives/lockable_struct/main.go
Normal file
@ -0,0 +1,20 @@
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
type Lockable[T any] struct {
|
||||
sync.Mutex
|
||||
Data T
|
||||
}
|
||||
|
||||
func main() {
|
||||
var l1 Lockable[int32]
|
||||
l1.Lock()
|
||||
l1.Data = 100
|
||||
l1.Unlock()
|
||||
|
||||
var l2 Lockable[string]
|
||||
l2.Lock()
|
||||
l2.Data = "test"
|
||||
l2.Unlock()
|
||||
}
|
||||
Reference in New Issue
Block a user