Skip to content

caiflower/common-tools

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

97 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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)
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages