common-tools

module
v0.0.0-...-806cc7c Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jan 24, 2025 License: Apache-2.0

README

common-tools

名称 路径 描述 修订 修订时间
自旋锁 github.com/caiflower/common-tools/syncx 自旋锁,拷贝自ants项目 2024-2-5
依赖注入 github.com/caiflower/common-tools/bean 自动注入ptr 2024-9-21

自旋锁

package main

import (
    "fmt"
    "github.com/caiflower/common-tools/pkg/syncx"
    "sync"
)

func main() {
    wait := sync.WaitGroup{}
    lock := syncx.NewSpinLock()
    var num int

    fn := func() {
        lock.Lock()
        num++
        lock.Unlock()
        wait.Done()
    }

    for i := 0; i < 10000; i++ {
        wait.Add(1)
        go fn()
    }

    wait.Wait()
    fmt.Printf("-----num=%v-----", num)
}

Directories

Path Synopsis
db
v1
env
kafka
v1
pkg
e
nio
redis
v1
test
web
e
v1

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL