Skip to content

Lock free data structures and patterns in Golang

License

Notifications You must be signed in to change notification settings

danielturin/lockfree

 
 

Repository files navigation

lockfree

WARNING: WIP, DO NOT USE in production

API Reference License Go version Github Actions Github Actions

Overview

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.

Data Structures

  • 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).

Extras

  • Reactor - lock-free reactor that provides thread-safe, non-blocking, asynchronous event processing.
    It uses lock-free queues for events and control messages.

Usage

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](256)

    core.Enqueue(ctx, q, []byte("hello ring buffer"))

    val, _ := core.Dequeue(ctx, q)
    fmt.Println(val)
}

Detailed examples of usage can be found in ./examples folder. Additionally, you can find more examples in tests and benchmarks.

Contributing

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.

License

lockfree is open-source software licensed under the MIT License. Feel free to use, modify, and distribute this library as permitted by the license.

About

Lock free data structures and patterns in Golang

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Go 97.8%
  • Makefile 2.2%