Categorygithub.com/caiflower/common-tools
module
0.0.0-20241211065842-b699784cd8ec
Repository: https://github.com/caiflower/common-tools.git
Documentation: pkg.go.dev

# README

common-tools

名称路径描述修订修订时间
自旋锁github.com/caiflower/common-tools/syncx自旋锁,拷贝自ants项目2024-2-5
依赖注入github.com/caiflower/common-tools/bean自动注入ptr2024-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)
}

# Packages

No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author
No description provided by the author