{"id":46627427,"url":"https://github.com/soenneker/soenneker.queues.intrusive.valuempsc","last_synced_at":"2026-03-11T00:11:47.748Z","repository":{"id":336531553,"uuid":"1150078417","full_name":"soenneker/soenneker.queues.intrusive.valuempsc","owner":"soenneker","description":"Provides a high performance mpsc intrusive queue primitive","archived":false,"fork":false,"pushed_at":"2026-03-07T13:46:50.000Z","size":61,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2026-03-08T03:11:58.664Z","etag":null,"topics":["csharp","dotnet","intrusive","mpsc","object","queue","queues","struct","valueintrusivempscqueue","valuempsc"],"latest_commit_sha":null,"homepage":"https://soenneker.com","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/soenneker.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":".github/CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":".github/CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":".github/SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"soenneker","thanks_dev":"soenneker"}},"created_at":"2026-02-04T21:21:58.000Z","updated_at":"2026-03-07T13:46:53.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/soenneker/soenneker.queues.intrusive.valuempsc","commit_stats":null,"previous_names":["soenneker/soenneker.queues.intrusive.valuempsc"],"tags_count":5,"template":false,"template_full_name":null,"purl":"pkg:github/soenneker/soenneker.queues.intrusive.valuempsc","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.queues.intrusive.valuempsc","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.queues.intrusive.valuempsc/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.queues.intrusive.valuempsc/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.queues.intrusive.valuempsc/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/soenneker","download_url":"https://codeload.github.com/soenneker/soenneker.queues.intrusive.valuempsc/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/soenneker%2Fsoenneker.queues.intrusive.valuempsc/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30360553,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-10T21:41:54.280Z","status":"ssl_error","status_checked_at":"2026-03-10T21:40:59.357Z","response_time":106,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.5:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["csharp","dotnet","intrusive","mpsc","object","queue","queues","struct","valueintrusivempscqueue","valuempsc"],"created_at":"2026-03-07T23:03:58.892Z","updated_at":"2026-03-11T00:11:47.739Z","avatar_url":"https://github.com/soenneker.png","language":"C#","funding_links":["https://github.com/sponsors/soenneker","https://thanks.dev/soenneker"],"categories":[],"sub_categories":[],"readme":"[![](https://img.shields.io/nuget/v/soenneker.queues.intrusive.valuempsc.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.queues.intrusive.valuempsc/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.queues.intrusive.valuempsc/publish-package.yml?style=for-the-badge)](https://github.com/soenneker/soenneker.queues.intrusive.valuempsc/actions/workflows/publish-package.yml)\n[![](https://img.shields.io/nuget/dt/soenneker.queues.intrusive.valuempsc.svg?style=for-the-badge)](https://www.nuget.org/packages/soenneker.queues.intrusive.valuempsc/)\n[![](https://img.shields.io/github/actions/workflow/status/soenneker/soenneker.queues.intrusive.valuempsc/codeql.yml?label=CodeQL\u0026style=for-the-badge)](https://github.com/soenneker/soenneker.queues.intrusive.valuempsc/actions/workflows/codeql.yml)\n\n# ![](https://user-images.githubusercontent.com/4441470/224455560-91ed3ee7-f510-4041-a8d2-3fc093025112.png) Soenneker.Queues.Intrusive.ValueMpsc\n### A zero-allocation, high-performance intrusive MPSC queue using value-based state\n\n---\n\n## Installation\n\n```bash\ndotnet add package Soenneker.Queues.Intrusive.ValueMpsc\n```\n\n---\n\n## Overview\n\n`ValueIntrusiveMpscQueue\u003cTNode\u003e` is a **multi-producer / single-consumer (MPSC)** queue built around a classic intrusive algorithm with a permanent sentinel (“stub”) node.\n\nThis *value* variant is designed to minimize indirection and memory traffic by storing queue state directly in value fields rather than reference wrappers.\n\nKey characteristics:\n\n* Multiple producers may enqueue concurrently.\n* Exactly one consumer may dequeue.\n* Each enqueue performs **a single atomic operation**.\n* **No allocations** are performed by the queue.\n* Node linkage is stored directly on the node (intrusive).\n* Queue state is held in value types for maximum locality and predictability.\n\nThis makes it especially suitable for **hot paths** in low-level concurrency primitives.\n\n---\n\n## Why a “Value” MPSC?\n\nCompared to reference-based implementations, this variant:\n\n* Avoids extra object indirection.\n* Reduces cache misses in contention-heavy scenarios.\n* Plays well with aggressive inlining and AOT scenarios.\n* Is easier to embed inside other value-centric primitives.\n\nIf you are building performance-critical infrastructure (locks, schedulers, wait queues), this version is usually the right default.\n\n---\n\n## Usage\n\n### Define a node type\n\nNodes must implement `IIntrusiveNode\u003cTNode\u003e` or derive from `IntrusiveNode\u003cTNode\u003e`.\n\n```csharp\npublic sealed class WorkItem : IntrusiveNode\u003cWorkItem\u003e\n{\n    public int Id;\n}\n```\n\nEach node carries its own linkage; the queue never allocates or wraps nodes.\n\n---\n\n### Create a queue with a permanent sentinel\n\n```csharp\nvar stub = new WorkItem();\nvar queue = new ValueIntrusiveMpscQueue\u003cWorkItem\u003e(stub);\n```\n\nThe stub node must remain alive for the entire lifetime of the queue.\n\n---\n\n### Enqueue (multi-producer)\n\n```csharp\nqueue.Enqueue(new WorkItem { Id = 42 });\n```\n\nThis operation is lock-free and safe to call concurrently from multiple threads.\n\n---\n\n### Dequeue (single-consumer)\n\n```csharp\nif (queue.TryDequeue(out var item))\n{\n    // process item\n}\n```\n\nIf stronger dequeue guarantees are required (for example, when a producer has advanced the tail but not yet published the link), use:\n\n```csharp\nqueue.TryDequeueSpin(out var item);\n```\n\n---\n\n## Correctness and constraints\n\nThis type intentionally enforces strict usage rules:\n\n* **Exactly one consumer thread** is supported.\n* A node must not be enqueued more than once at a time.\n* Nodes may be reused only after being dequeued.\n* The sentinel (stub) node must remain alive for the queue’s lifetime.\n* `TryDequeue` may return `false` while a producer is mid-enqueue — this is expected.\n\nViolating these constraints will result in undefined behavior.\n\nThis is a **low-level primitive**, not a general-purpose collection.\n\n---\n\n## When to use this\n\nThis queue is a good fit when:\n\n* You are building synchronization primitives (async locks, semaphores, schedulers).\n* Allocation-free behavior is mandatory.\n* You need tight control over memory ordering and visibility.\n* You can enforce a single-consumer contract.\n* You care about instruction count, cache locality, and predictable latency.\n\nIf you need a general-purpose queue with multiple consumers, prefer `ConcurrentQueue\u003cT\u003e` or `System.Threading.Channels`.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.queues.intrusive.valuempsc","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsoenneker%2Fsoenneker.queues.intrusive.valuempsc","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsoenneker%2Fsoenneker.queues.intrusive.valuempsc/lists"}