Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/smallnest/queue
lock-free queue and other implementations
https://github.com/smallnest/queue
Last synced: 5 days ago
JSON representation
lock-free queue and other implementations
- Host: GitHub
- URL: https://github.com/smallnest/queue
- Owner: smallnest
- License: mit
- Created: 2020-08-07T11:39:58.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2023-10-17T03:33:42.000Z (about 1 year ago)
- Last Synced: 2024-08-03T17:18:29.420Z (3 months ago)
- Language: Go
- Size: 12.7 KB
- Stars: 126
- Watchers: 3
- Forks: 19
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# queue
```go
import "github.com/smallnest/queue"
```
Package queue provides multiple queue implementations.
The lock-free and two-lock algorithms are from Michael and Scott. https://doi.org/10.1145/248052.248106## Queue
A queue is a collection of entities that are maintained in a sequence and can be modified by the addition of entities at one end of the sequence and the removal of entities from the other end of the sequence.The operations of a queue make it a first-in-first-out (FIFO) data structure. In a FIFO data structure, the first element added to the queue will be the first one to be removed.
Package queue defines `Queue` interface:
```go
type Queue[T any] interface {
Enqueue(v T)
Dequeue() T
}
```Currently it contains three implementations:
- lock-free queue: `LKQueue`
- two-lock queue: `CQueue`
- slice-based queue: `SliceQueue`## Benchmark
```sh
goos: darwin
goarch: amd64
pkg: github.com/smallnest/queueBenchmarkQueue/lock-free_queue#4-8 4835329 266.2 ns/op 16 B/op 1 allocs/op
BenchmarkQueue/two-lock_queue#4-8 9112242 168.0 ns/op 16 B/op 1 allocs/op
BenchmarkQueue/slice-based_queue#4-8 8778811 182.0 ns/op 40 B/op 0 allocs/opBenchmarkQueue/two-lock_queue#32-8 9109314 133.1 ns/op 16 B/op 1 allocs/op
BenchmarkQueue/slice-based_queue#32-8 7939176 171.8 ns/op 54 B/op 0 allocs/op
BenchmarkQueue/lock-free_queue#32-8 4735264 253.8 ns/op 16 B/op 1 allocs/opBenchmarkQueue/lock-free_queue#1024-8 4654297 242.6 ns/op 16 B/op 1 allocs/op
BenchmarkQueue/two-lock_queue#1024-8 7714422 138.2 ns/op 16 B/op 1 allocs/op
BenchmarkQueue/slice-based_queue#1024-8 8609463 169.7 ns/op 34 B/op 0 allocs/op
```