Soenneker.Queues.Intrusive.ValueMpsc
4.0.24
Prefix Reserved
See the version list below for details.
dotnet add package Soenneker.Queues.Intrusive.ValueMpsc --version 4.0.24
NuGet\Install-Package Soenneker.Queues.Intrusive.ValueMpsc -Version 4.0.24
<PackageReference Include="Soenneker.Queues.Intrusive.ValueMpsc" Version="4.0.24" />
<PackageVersion Include="Soenneker.Queues.Intrusive.ValueMpsc" Version="4.0.24" />
<PackageReference Include="Soenneker.Queues.Intrusive.ValueMpsc" />
paket add Soenneker.Queues.Intrusive.ValueMpsc --version 4.0.24
#r "nuget: Soenneker.Queues.Intrusive.ValueMpsc, 4.0.24"
#:package Soenneker.Queues.Intrusive.ValueMpsc@4.0.24
#addin nuget:?package=Soenneker.Queues.Intrusive.ValueMpsc&version=4.0.24
#tool nuget:?package=Soenneker.Queues.Intrusive.ValueMpsc&version=4.0.24
Soenneker.Queues.Intrusive.ValueMpsc
A zero-allocation, high-performance intrusive MPSC queue using value-based state
Installation
dotnet add package Soenneker.Queues.Intrusive.ValueMpsc
Overview
ValueIntrusiveMpscQueue<TNode> is a multi-producer / single-consumer (MPSC) queue built around a classic intrusive algorithm with a permanent sentinel (“stub”) node.
This value variant is designed to minimize indirection and memory traffic by storing queue state directly in value fields rather than reference wrappers.
Key characteristics:
- Multiple producers may enqueue concurrently.
- Exactly one consumer may dequeue.
- Each enqueue performs a single atomic operation.
- No allocations are performed by the queue.
- Node linkage is stored directly on the node (intrusive).
- Queue state is held in value types for maximum locality and predictability.
This makes it especially suitable for hot paths in low-level concurrency primitives.
Why a “Value” MPSC?
Compared to reference-based implementations, this variant:
- Avoids extra object indirection.
- Reduces cache misses in contention-heavy scenarios.
- Plays well with aggressive inlining and AOT scenarios.
- Is easier to embed inside other value-centric primitives.
If you are building performance-critical infrastructure (locks, schedulers, wait queues), this version is usually the right default.
Usage
Define a node type
Nodes must implement IIntrusiveNode<TNode> or derive from IntrusiveNode<TNode>.
public sealed class WorkItem : IntrusiveNode<WorkItem>
{
public int Id;
}
Each node carries its own linkage; the queue never allocates or wraps nodes.
Create a queue with a permanent sentinel
var stub = new WorkItem();
var queue = new ValueIntrusiveMpscQueue<WorkItem>(stub);
The stub node must remain alive for the entire lifetime of the queue.
Enqueue (multi-producer)
queue.Enqueue(new WorkItem { Id = 42 });
This operation is lock-free and safe to call concurrently from multiple threads.
Dequeue (single-consumer)
if (queue.TryDequeue(out var item))
{
// process item
}
If stronger dequeue guarantees are required (for example, when a producer has advanced the tail but not yet published the link), use:
queue.TryDequeueSpin(out var item);
Correctness and constraints
This type intentionally enforces strict usage rules:
- Exactly one consumer thread is supported.
- A node must not be enqueued more than once at a time.
- Nodes may be reused only after being dequeued.
- The sentinel (stub) node must remain alive for the queue’s lifetime.
TryDequeuemay returnfalsewhile a producer is mid-enqueue — this is expected.
Violating these constraints will result in undefined behavior.
This is a low-level primitive, not a general-purpose collection.
When to use this
This queue is a good fit when:
- You are building synchronization primitives (async locks, semaphores, schedulers).
- Allocation-free behavior is mandatory.
- You need tight control over memory ordering and visibility.
- You can enforce a single-consumer contract.
- You care about instruction count, cache locality, and predictable latency.
If you need a general-purpose queue with multiple consumers, prefer ConcurrentQueue<T> or System.Threading.Channels.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Soenneker.Queues.Intrusive.Abstractions (>= 4.0.14)
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Queues.Intrusive.ValueMpsc:
| Package | Downloads |
|---|---|
|
Soenneker.Asyncs.Locks
The fastest .NET async lock. |
|
|
Soenneker.Asyncs.Semaphores
A low-allocation asynchronous semaphore for bounded in-process concurrency. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.46 | 37 | 10/11/2026 |
| 4.0.45 | 53 | 10/11/2026 |
| 4.0.44 | 94,524 | 9/28/2026 |
| 4.0.43 | 42,594 | 9/24/2026 |
| 4.0.42 | 7,025 | 9/24/2026 |
| 4.0.41 | 90,958 | 9/15/2026 |
| 4.0.40 | 108 | 9/15/2026 |
| 4.0.39 | 77,556 | 9/12/2026 |
| 4.0.38 | 352 | 9/12/2026 |
| 4.0.37 | 106 | 9/12/2026 |
| 4.0.36 | 255,992 | 9/3/2026 |
| 4.0.35 | 105 | 9/3/2026 |
| 4.0.34 | 56,416 | 8/31/2026 |
| 4.0.33 | 121 | 8/30/2026 |
| 4.0.32 | 33,858 | 8/30/2026 |
| 4.0.31 | 111 | 8/29/2026 |
| 4.0.30 | 274,757 | 8/8/2026 |
| 4.0.29 | 109,174 | 7/28/2026 |
| 4.0.28 | 131 | 7/28/2026 |
| 4.0.24 | 136 | 6/18/2026 |
Update actions/checkout action to v7 (#102)
Automatically merged