A lock-free single producer, single consumer ringbuffer implementation in Go using atomic operations.
go get github.com/minhthong582000/atomicringbufferimport "github.com/minhthong582000/atomicringbuffer"Construct a new ringbuffer with a given size and type T:
rb := atomicringbuffer.NewRingBuffer[int](1024) // capacity = 1024, type = intPush 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)A simple example of lock-free single producer, single consumer:
go run example/spsc/main.goFeel 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!
Distributed under the GPLv3 License. See LICENSE.md file for more information.