WARNING: WIP, DO NOT USE in production
Lock-free data structures implemented with native Golang, based on atomic compare-and-swap operations. These lock-free data structures are designed to provide concurrent access without relying on traditional locking mechanisms, improving performance and scalability in highly concurrent environments.
- LL Stack - lock-free stack based on a linked list with
atomic.Pointer
elements. - LL Queue - lock-free queue based on a linked list with
atomic.Pointer
elements. - RB Queue - lock-free queue based on a ring buffer that uses a capped slice of
atomic.Pointer
elements.
NOTE: lock based data structures were implemented for benchmarking purposes (lock based ring buffer and channel based queue).
- Reactor - lock-free reactor that provides thread-safe, non-blocking, asynchronous event processing.
It uses a demultiplexer that is based on lock-free queues for events and control messages. - Pool Wrapper - wraps a function that is using some pooled resource.
go get github.com/amirylm/lockfree
import (
"github.com/amirylm/lockfree/ringbuffer"
"github.com/amirylm/lockfree/core"
)
func main() {
ctx, cancel := context.WithCancel(context.Backgorund())
defer cancel()
q := ringbuffer.New[[]byte](core.WithCapacity(256))
q.Enqueue([]byte("hello ring buffer"))
val, _ := q.Dequeue()
fmt.Println(val)
}
Detailed examples of usage can be found in ./examples
folder.
Additionally, you can find more examples in tests and benchmarks.
Contributions to lockfree are welcomed and encouraged! If you find a bug or have an idea for an improvement, please open an issue or submit a pull request.
Before contributing, please make sure to read the Contributing Guidelines for more information.
lockfree is open-source software licensed under the MIT License. Feel free to use, modify, and distribute this library as permitted by the license.