An open API service indexing awesome lists of open source software.

https://github.com/minhthong582000/atomicringbuffer

A lock-free single producer, single consumer ringbuffer implementation in Go
https://github.com/minhthong582000/atomicringbuffer

circular-queue go lock-free ring-buffer

Last synced: 11 months ago
JSON representation

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

Awesome Lists containing this project

README

          

# Ringbuffer

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

## Installation

```bash
go get github.com/minhthong582000/atomicringbuffer
```

## Usage

```go
import "github.com/minhthong582000/atomicringbuffer"
```

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

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

Push an item to the back of the ringbuffer:

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

Pop an item from the front of the ringbuffer:

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

fmt.Println(item)
```

## Simple Example

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

```bash
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.