Lock-free, non-blocking MPMC queues.
Project description
nblf-queue
Non-Blocking Lock-Free Queue
An atomic lock-free MPMC queue based on the NBLFQ algorithm.
This repository provides multiple queue implementations with different storage and allocation strategies.
All queues in this repository are safe to use in a concurrent context and will never block the calling thread.
Queue variants
- Static queues: fixed-capacity queues backed by static storage
- Allocated queues: fixed-capacity queues backed by dynamically allocated storage, only available on feature
alloc - Dynamic queues: dynamically growable queues, only available on feature
dynamic - Pooled Queues: variants of other queues, which may store arbitrary types, only available on feature
pool
Non-pooled queues store items in atomically updated slots, restricting the stored items to small, pointer-like values.
Usage
nblf_queue::StaticQueue:
use nblf_queue::{StaticQueue, MPMCQueue};
let q: StaticQueue<_, 2> = StaticQueue::new();
assert!(q.push(&42).is_ok());
assert!(q.push(&1).is_ok());
assert!(q.push(&4242).is_err());
assert_eq!(q.pop(), Some(&42));
assert_eq!(q.pop(), Some(&1));
assert!(q.pop().is_none());
nblf_queue::PooledStaticQueue:
#[cfg(feature = "pool")]
fn run() {
use nblf_queue::{PooledStaticQueue, MPMCQueue};
let q: PooledStaticQueue<_, 2> = PooledStaticQueue::new();
assert!(q.push(42).is_ok());
assert!(q.push(1).is_ok());
assert!(q.push(4242).is_err());
assert_eq!(q.pop(), Some(42));
assert_eq!(q.pop(), Some(1));
assert!(q.pop().is_none());
}
#[cfg(feature = "pool")]
run();
Choosing a queue type
StaticQueue and Queue may only store small values and are optimized for this use case.
PooledStaticQueue and PooledQueue may store arbitrary types, at the cost of higher memory usage and runtime cost.
DynamicQueue and PooledDynamicQueue may be grown dynamically, at the cost of higher total memory usage and runtime cost. This is cost is even higher for PooledDynamicQueue.
Platform Support
Multiple storage types are available, dependent on platform:
-
Tagged64 - platforms with native 64-bit atomic operations or feature
atomic-fallback -
Tagged128 - platforms with native 128-bit atomic operations or feature
atomic-fallback
Storage types will be chosen automatically, unless sepcified explicitly.
[!NOTE] ABA Safety & Storage Selection If it is plausible that other threads could perform
(2^15 - 1) * queue_sizepop and push operations while a single thread is paused/preempted in pop/push,Tagged128slots should be used to ensure ABA safety.
Feature Flags
-
std: Enablesstdandallocsupport -
alloc: Enablesallocsupport, allowing usage of some dynamically allocated queues -
pool: Enables pooled queues, which may store any type -
dynamic: Enables dynamic queues, which may dynamically grow -
atomic-fallback: Usesportable-atomicfallbackfeature for atomics if necessary. It is discouraged to use this feature, asfallbackinternally uses locks -
default:pool
Python Bindings
Python bindings backed by PooledQueue and PooledDynamicQueue are available for concurrent applications.
Core operations detach from the GIL to allow parallel execution.
[!NOTE] The Python bindings strictly use
Autoslots without featureatomic-fallback. As a result, these bindings are only supported on platforms with native 64-bit or 128-bit atomic operations.
from nblf_queue import Queue, DynamicQueue
q: Queue[int] = Queue(10)
q.push(42)
item = q.pop()
assert item == 42
dq: DynamicQueue[str] = DynamicQueue(5)
dq.push("hello")
dq.grow()
Testing
The core test-suite of this crate was adapted from crossbeam-queue.
Current testing is based on:
- Miri - to validate pointer arithmetic and catch UB
- Loom and Shuttle - to test for race conditions
- ASan - to check for memory corruption and leakage
References
Alexandre Denis, Charles Goedefroit. NBLFQ: a lock-free MPMC queue optimized for low contention. IPDPS 2025 - 39th International Parallel & Distributed Processing Symposium, IEEE, Jun 2025, Milan, Italy. hal-04851700v2
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distributions
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file nblf_queue-0.1.0.tar.gz.
File metadata
- Download URL: nblf_queue-0.1.0.tar.gz
- Upload date:
- Size: 521.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fe608ea62ff55801174464a96e7d8598e374ea2b8e6662ab56f5859893db1cc8
|
|
| MD5 |
f51e53a28b2a9ce66419a79bbafbb15d
|
|
| BLAKE2b-256 |
53d559d66a26258167b474dbb44c17dfafd44bac67385551a6770cd27ae798c0
|
Provenance
The following attestation bundles were made for nblf_queue-0.1.0.tar.gz:
Publisher:
pypi_release.yml on lmeller-git/nblf-queue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nblf_queue-0.1.0.tar.gz -
Subject digest:
fe608ea62ff55801174464a96e7d8598e374ea2b8e6662ab56f5859893db1cc8 - Sigstore transparency entry: 1915283509
- Sigstore integration time:
-
Permalink:
lmeller-git/nblf-queue@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lmeller-git
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nblf_queue-0.1.0-cp312-abi3-win_amd64.whl.
File metadata
- Download URL: nblf_queue-0.1.0-cp312-abi3-win_amd64.whl
- Upload date:
- Size: 125.4 kB
- Tags: CPython 3.12+, Windows x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
664cebcb59eca2b128ca5e0b48e19282d8b5e3e376f55e8bca886ac93a36b90e
|
|
| MD5 |
e4fdc1b130667f81125462edc5aa88e9
|
|
| BLAKE2b-256 |
cbefc98709b31b21486f244a282110af82eb0aead743301df4f0a1a6fba20004
|
Provenance
The following attestation bundles were made for nblf_queue-0.1.0-cp312-abi3-win_amd64.whl:
Publisher:
pypi_release.yml on lmeller-git/nblf-queue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nblf_queue-0.1.0-cp312-abi3-win_amd64.whl -
Subject digest:
664cebcb59eca2b128ca5e0b48e19282d8b5e3e376f55e8bca886ac93a36b90e - Sigstore transparency entry: 1915284043
- Sigstore integration time:
-
Permalink:
lmeller-git/nblf-queue@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lmeller-git
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nblf_queue-0.1.0-cp312-abi3-macosx_11_0_arm64.whl.
File metadata
- Download URL: nblf_queue-0.1.0-cp312-abi3-macosx_11_0_arm64.whl
- Upload date:
- Size: 228.3 kB
- Tags: CPython 3.12+, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e1804baa3aa1fd75ff6a320f6ad9057bc9936aa01e1a561195d2839ca4eb490e
|
|
| MD5 |
c71fc0fd14133952b2b8c16cc50c8078
|
|
| BLAKE2b-256 |
3250e6ee2d300ac2b360ae129543ffbe8e05f3612f5bb9a08ef7fcae293938e5
|
Provenance
The following attestation bundles were made for nblf_queue-0.1.0-cp312-abi3-macosx_11_0_arm64.whl:
Publisher:
pypi_release.yml on lmeller-git/nblf-queue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nblf_queue-0.1.0-cp312-abi3-macosx_11_0_arm64.whl -
Subject digest:
e1804baa3aa1fd75ff6a320f6ad9057bc9936aa01e1a561195d2839ca4eb490e - Sigstore transparency entry: 1915284156
- Sigstore integration time:
-
Permalink:
lmeller-git/nblf-queue@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lmeller-git
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nblf_queue-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl.
File metadata
- Download URL: nblf_queue-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl
- Upload date:
- Size: 232.8 kB
- Tags: CPython 3.12+, macOS 10.12+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
beaed52e5cb49c95eede4f6c0a40920564f545c490899e2f28637d695052415e
|
|
| MD5 |
a947524e436fa4f61e8d9faed1e3463b
|
|
| BLAKE2b-256 |
d36aba8a99c9d4145233c2d73da3b192128929de8449b2c45ed11181ec30c8c8
|
Provenance
The following attestation bundles were made for nblf_queue-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl:
Publisher:
pypi_release.yml on lmeller-git/nblf-queue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nblf_queue-0.1.0-cp312-abi3-macosx_10_12_x86_64.whl -
Subject digest:
beaed52e5cb49c95eede4f6c0a40920564f545c490899e2f28637d695052415e - Sigstore transparency entry: 1915283640
- Sigstore integration time:
-
Permalink:
lmeller-git/nblf-queue@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lmeller-git
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file nblf_queue-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.
File metadata
- Download URL: nblf_queue-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
- Upload date:
- Size: 275.0 kB
- Tags: CPython 3.9+, manylinux: glibc 2.17+ x86-64
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c9aceb07118c00751cc1fe8091935a6fc52bd731ef4d122bc30a9cadf53dbd96
|
|
| MD5 |
2967db04fbb0393fc5cd669a628f827b
|
|
| BLAKE2b-256 |
1b63b2d1dab72fab1c23e51da79e4ab8c99131d2f317a436105e6a9286724dd0
|
Provenance
The following attestation bundles were made for nblf_queue-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl:
Publisher:
pypi_release.yml on lmeller-git/nblf-queue
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nblf_queue-0.1.0-cp39-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl -
Subject digest:
c9aceb07118c00751cc1fe8091935a6fc52bd731ef4d122bc30a9cadf53dbd96 - Sigstore transparency entry: 1915283929
- Sigstore integration time:
-
Permalink:
lmeller-git/nblf-queue@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Branch / Tag:
refs/heads/main - Owner: https://github.com/lmeller-git
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi_release.yml@50d3206c3642f8c1a8f5cb2fca3bf6ee17cd415a -
Trigger Event:
workflow_dispatch
-
Statement type: