Skip to content

minhthong582000/atomicringbuffer

Repository files navigation

Ringbuffer

A lock-free single producer, single consumer ringbuffer implementation in Go using atomic operations.

Installation

go get github.com/minhthong582000/atomicringbuffer

Usage

import "github.com/minhthong582000/atomicringbuffer"

Construct a new ringbuffer with a given size and type T:

rb := atomicringbuffer.NewRingBuffer[int](1024) // capacity = 1024, type = int

Push an item to the back of the ringbuffer:

err := rb.PushBack(2)
if err != nil {
    // Handle error
}

Pop an item from the front of the ringbuffer:

item, err := rb.PopFront()
if err != nil {
    // Handle error
}

fmt.Println(item)

Simple Example

A simple example of lock-free single producer, single consumer:

go run example/spsc/main.go

Contributing

Feel free to fork or clone this repository, explore the code, and contribute by submitting pull requests. Contributions, whether they’re bug fixes, improvements, or new features, are always welcome!

License

Distributed under the GPLv3 License. See LICENSE.md file for more information.

About

A lock-free single producer, single consumer ringbuffer implementation in Go

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages