Soenneker.Queues.Intrusive.Mpsc
4.0.22
Prefix Reserved
dotnet add package Soenneker.Queues.Intrusive.Mpsc --version 4.0.22
NuGet\Install-Package Soenneker.Queues.Intrusive.Mpsc -Version 4.0.22
<PackageReference Include="Soenneker.Queues.Intrusive.Mpsc" Version="4.0.22" />
<PackageVersion Include="Soenneker.Queues.Intrusive.Mpsc" Version="4.0.22" />
<PackageReference Include="Soenneker.Queues.Intrusive.Mpsc" />
paket add Soenneker.Queues.Intrusive.Mpsc --version 4.0.22
#r "nuget: Soenneker.Queues.Intrusive.Mpsc, 4.0.22"
#:package Soenneker.Queues.Intrusive.Mpsc@4.0.22
#addin nuget:?package=Soenneker.Queues.Intrusive.Mpsc&version=4.0.22
#tool nuget:?package=Soenneker.Queues.Intrusive.Mpsc&version=4.0.22
Soenneker.Queues.Intrusive.Mpsc
High-performance intrusive multi-producer / single-consumer (MPSC) queue primitive.
This package provides a lock-free, allocation-free MPSC queue designed for low-level concurrency primitives and async infrastructure. It is intended for advanced usage where control over memory layout, allocation, and synchronization semantics is required.
Installation
dotnet add package Soenneker.Queues.Intrusive.Mpsc
Overview
IntrusiveMpscQueue<TNode> implements a classic MPSC algorithm using a permanent sentinel (stub) node:
- Multiple producer threads may enqueue concurrently.
- Exactly one consumer thread may dequeue.
- Each enqueue performs a single atomic operation.
- No allocations are performed by the queue itself.
- Node linkage is stored directly on the node (intrusive).
This design is well suited for wait queues, schedulers, async locks, and similar primitives.
Usage
Define a node type
Nodes must implement IIntrusiveNode<TNode> or derive from IntrusiveNode<TNode>.
public sealed class WorkItem : IntrusiveNode<WorkItem>
{
public int Id;
}
Create a queue with a permanent stub
var stub = new WorkItem();
var queue = new IntrusiveMpscQueue<WorkItem>(stub);
Enqueue (multi-producer)
queue.Enqueue(new WorkItem { Id = 42 });
Dequeue (single-consumer)
if (queue.TryDequeue(out var item))
{
// process item
}
If stronger dequeue semantics are required (for example, when a producer has advanced the tail but not yet published the link), use TryDequeueSpin.
Correctness and constraints
- Exactly one consumer thread is supported.
- A node must not be enqueued while it is already enqueued.
- Node reuse is allowed only after the node has been dequeued.
- The sentinel (stub) node must remain alive for the lifetime of the queue.
TryDequeuemay returnfalseeven when a producer is mid-enqueue; this is expected behavior.
This type is not intended as a general-purpose collection.
When to use this
This queue is appropriate when:
- You are building synchronization primitives (locks, semaphores, schedulers).
- Allocation-free behavior is required.
- You need precise control over memory ordering and concurrency behavior.
- You can enforce a single-consumer contract.
If you need a general-purpose, multi-consumer queue, use System.Threading.Channels or ConcurrentQueue<T> instead.
| 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.15)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.22 | 0 | 6/19/2026 |
| 4.0.21 | 94 | 6/5/2026 |
| 4.0.20 | 101 | 6/5/2026 |
| 4.0.19 | 106 | 6/5/2026 |
| 4.0.18 | 109 | 4/23/2026 |
| 4.0.17 | 105 | 4/23/2026 |
| 4.0.16 | 118 | 3/13/2026 |
| 4.0.15 | 108 | 3/12/2026 |
| 4.0.14 | 108 | 3/12/2026 |
| 4.0.13 | 115 | 3/12/2026 |
| 4.0.12 | 107 | 3/12/2026 |
| 4.0.11 | 118 | 3/12/2026 |
| 4.0.10 | 107 | 3/11/2026 |
| 4.0.9 | 104 | 3/10/2026 |
| 4.0.8 | 114 | 3/10/2026 |
| 4.0.7 | 115 | 3/9/2026 |
| 4.0.6 | 107 | 3/9/2026 |
| 4.0.5 | 105 | 3/9/2026 |
| 4.0.3 | 116 | 2/4/2026 |
| 4.0.2 | 113 | 2/4/2026 |
Update dependency Soenneker.Queues.Intrusive.Abstractions to 4.0.15 (#30)