Soenneker.Queues.Intrusive.ValueMpsc 4.0.18

Prefix Reserved
dotnet add package Soenneker.Queues.Intrusive.ValueMpsc --version 4.0.18
                    
NuGet\Install-Package Soenneker.Queues.Intrusive.ValueMpsc -Version 4.0.18
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Soenneker.Queues.Intrusive.ValueMpsc" Version="4.0.18" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Queues.Intrusive.ValueMpsc" Version="4.0.18" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Queues.Intrusive.ValueMpsc" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Queues.Intrusive.ValueMpsc --version 4.0.18
                    
#r "nuget: Soenneker.Queues.Intrusive.ValueMpsc, 4.0.18"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Soenneker.Queues.Intrusive.ValueMpsc@4.0.18
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Queues.Intrusive.ValueMpsc&version=4.0.18
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Queues.Intrusive.ValueMpsc&version=4.0.18
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

alternate text is missing from this package README image 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.
  • TryDequeue may return false while 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Soenneker.Queues.Intrusive.ValueMpsc:

Package Downloads
Soenneker.Asyncs.Locks

The fastest .NET async lock.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.0.18 100,592 3/13/2026
4.0.17 88 3/12/2026
4.0.16 87 3/12/2026
4.0.15 88 3/12/2026
4.0.14 94 3/12/2026
4.0.13 98 3/12/2026
4.0.12 76,663 3/11/2026
4.0.11 91 3/10/2026
4.0.10 24,714 3/10/2026
4.0.9 88 3/9/2026
4.0.8 89 3/9/2026
4.0.7 85 3/9/2026
4.0.5 280,098 2/4/2026
4.0.4 94 2/4/2026
4.0.3 92 2/4/2026
4.0.2 96 2/4/2026
4.0.1 95 2/4/2026

Update dependency Soenneker.Queues.Intrusive.Abstractions to 4.0.11 (#34)