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
- Host: GitHub
- URL: https://github.com/minhthong582000/atomicringbuffer
- Owner: minhthong582000
- License: gpl-3.0
- Created: 2025-01-04T12:03:09.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-01-12T10:40:26.000Z (about 1 year ago)
- Last Synced: 2025-01-12T11:29:37.449Z (about 1 year ago)
- Topics: circular-queue, go, lock-free, ring-buffer
- Language: Go
- Homepage:
- Size: 17.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
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.