Исходники и презентации
This commit is contained in:
35
lessons/sync_primitives/mutex_operations/main.go
Normal file
35
lessons/sync_primitives/mutex_operations/main.go
Normal file
@ -0,0 +1,35 @@
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
func lockAnyTimes() {
|
||||
mutex := sync.Mutex{}
|
||||
mutex.Lock()
|
||||
mutex.Lock()
|
||||
}
|
||||
|
||||
func unlockWithoutLock() {
|
||||
mutex := sync.Mutex{}
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
func unlockFromAnotherGoroutine() {
|
||||
mutex := sync.Mutex{}
|
||||
mutex.Lock()
|
||||
|
||||
wg := sync.WaitGroup{}
|
||||
wg.Add(1)
|
||||
|
||||
go func() {
|
||||
defer wg.Done()
|
||||
mutex.Unlock()
|
||||
}()
|
||||
|
||||
wg.Wait()
|
||||
|
||||
mutex.Lock()
|
||||
mutex.Unlock()
|
||||
}
|
||||
|
||||
func main() {
|
||||
}
|
||||
Reference in New Issue
Block a user