mirror of
https://gitee.com/johng/gf.git
synced 2024-12-03 20:58:47 +08:00
24 lines
323 B
Go
24 lines
323 B
Go
package main
|
|
|
|
import (
|
|
"sync"
|
|
|
|
"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, 1000)
|
|
glog.Println(i)
|
|
wg.Done()
|
|
}(i)
|
|
}
|
|
wg.Wait()
|
|
}
|