Generates thread safe accessors for specialized types.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Matt Skinner d5673d60fd Upgrade packages and fix import paths. 1 year ago
public CIDC and de-linting. 1 year ago
slice CIDC and de-linting. 1 year ago
slicer Upgrade packages and fix import paths. 1 year ago
.gitignore CIDC and de-linting. 1 year ago
.gitlab-ci.yml Update .gitlab-ci.yml 1 year ago
LICENSE Initial commit. 2 years ago
README.md Update README.md 1 year ago
go.mod Upgrade packages and fix import paths. 1 year ago
go.sum Upgrade packages and fix import paths. 1 year ago
main.go Fix import paths and module path. 1 year ago

README.md

pipeline status coverage report

Coverage Report

AtomicSlicer

AtomicSlicer is a GoLang generation tool that generates code for accessing slices of structures and interfaces in a thread safe manner. When using go-routines it is common to collect results in a slice, but slices in GoLang are not thread-safe.

For example to append a string the slice itself is modified:

var stringSlice []string
stringSlice := append(stringSlice, "myString")

QuickStart

Suppose there is a structure:

type MyStruct struct {
	Field1 int
	Field2 string
	// and more fields
}

If we want to access a slice of MyStruct concurrently, we can generate the code with:

//go:generate atomicslicer MyStruct

A file will be generated starting with generated_ and place in the same directory wherever MyStruct is defined.

We can then create and access a slice of MyStruct via methods:

package example

import(
	"sync"
)

type MyStruct struct {
	Field1 int
	Field2 string
	// and more fields
}

func main() {
	myStructSlice := NewMyStructAtomicSlice()
    waitGroup := new(sync.WaitGroup)
    
    for i := 0; i < 100; i++ {
    	go func(i int) {
    			myStructSlice.Append(&MyStruct{Field1: i})
    	}(i)
    }
}

In this contrived example, we iterate a hundred times creating a Go-routine in each iteration. In the Go-routine, we append to the slice.