Skip to content

go-ng/xatomic

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

xatomic

GoDoc

About

This package just provides with additional primitives to available in sync/atomic.

Right now it provides with only 4 functions:

Examples

Pointer

import "github.com/go-ng/xatomic"

    ...
    var m *myStruct
    ...
    go func(){
        ...
        xatomic.StorePointer(&m, &myStruct{Err: myErr})
        ...
    }()
    go func(){
        ...
        fmt.Println(xatomic.LoadPointer(&m).Err.Error())
        ...
    }()

Slice

import "github.com/go-ng/xatomic"


    ...
    var m map[string]any{}
    ...
    go func(){
        ...
        xatomic.StoreMap(m, myMap)
        ...
    }()
    go func(){
        ...
        myMap := xatomic.LoadMap(m)
        ...
    }()

It uses Go generics, so the type of the map is preserved after StoreMap & LoadMap.

Performance

goos: linux
goarch: amd64
pkg: github.com/go-ng/xatomic
cpu: 11th Gen Intel(R) Core(TM) i7-11800H @ 2.30GHz
Benchmark/noop-16                     	1000000000	         0.2236 ns/op
Benchmark/Map/Store/atomic-16         	987858870	         6.108 ns/op
Benchmark/Map/Store/unatomic-16       	1000000000	         0.3973 ns/op
Benchmark/Map/Load/atomic-16          	1000000000	         0.4589 ns/op
Benchmark/Map/Load/unatomic-16        	1000000000	         0.4611 ns/op
PASS
ok  	github.com/go-ng/xatomic	8.364s

About

Extensions to sync/atomic

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages