mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 04:37:49 +08:00
27 lines
365 B
Go
27 lines
365 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
"time"
|
|
|
|
"github.com/gogf/gf/os/glog"
|
|
"github.com/gogf/gf/os/gmlock"
|
|
)
|
|
|
|
// 内存锁基本使用
|
|
func main() {
|
|
key := "lock"
|
|
wg := sync.WaitGroup{}
|
|
for i := 0; i < 10; i++ {
|
|
wg.Add(1)
|
|
go func(i int) {
|
|
gmlock.Lock(key)
|
|
glog.Println(i)
|
|
time.Sleep(time.Second)
|
|
gmlock.Unlock(key)
|
|
wg.Done()
|
|
}(i)
|
|
}
|
|
wg.Wait()
|
|
}
|