Исходники и презентации
This commit is contained in:
21
lessons/sync_primitives/defer_with_mutex/main.go
Normal file
21
lessons/sync_primitives/defer_with_mutex/main.go
Normal file
@ -0,0 +1,21 @@
|
||||
package main
|
||||
|
||||
import "sync"
|
||||
|
||||
// Need to show solution
|
||||
|
||||
var mutex sync.Mutex
|
||||
|
||||
func operation() {}
|
||||
|
||||
func doSomething() {
|
||||
mutex.Lock()
|
||||
operation()
|
||||
mutex.Unlock()
|
||||
|
||||
// some long operation
|
||||
|
||||
mutex.Lock()
|
||||
operation()
|
||||
mutex.Unlock()
|
||||
}
|
||||
Reference in New Issue
Block a user