Summary
This proposal introduces two sets of pure C# features ported from Rust's standard library and crossbeam-queue, to extend DotNext's atomic operation and lock-free queue capabilities. I have completed the full implementation, and I want to confirm the adaptation requirements before submitting a PR.
1. New Atomic Structure Encapsulation
Feature Overview
Add Rust-style atomic wrapper structures for common numeric types, including int, long, as well as platform-sized types AtomicIsize (nint) and AtomicUsize (nuint).
This set of wrappers unifies scattered Volatile and Interlocked API calls, and exposes explicit memory ordering parameters to control atomic memory behavior consistently following Rust atomic design.
Core Capabilities
- Covers most existing
Interlocked atomic operations: read/write, exchange, compare-exchange, increment, decrement.
- Adds extended atomic bitwise operations:
And, Or, Xor.
- Supports full memory ordering semantics:
Relaxed, Acquire, Release, AcqRel, SeqCst.
- Provides two unified entry points for all atomic types:
T Load(Ordering order)
void Store(T value, Ordering order)
- Supports both 32-bit and 64-bit process environments.
Implementation Basis
Implemented based on standard .NET Unsafe and Interlocked APIs. The code can be refactored to match DotNext existing architecture and code style.
Source: AtomicHelpers.cs
2. GC-Free Lock-Free Queue: SegQueue & ArrayQueue
Feature Overview
Ported Rust crossbeam-queue's SegQueue and ArrayQueue to pure C#. The implementations work only with unmanaged types, suitable for GC-sensitive scenarios.
Core Features
- Fully GC-free, allocated on unmanaged memory.
- MPMC lock-free concurrent queue design.
- Pure C# cross-platform implementation.
Implementation Basis
Full pure C# port implementation: crossbeam-queue C# Port
3. PR Adaptation Consultation & Next Steps
All features are fully implemented. I intend to submit a PR to integrate them into DotNext. I would like to clarify the project requirements for adaptation:
- Code style, naming convention and namespace rules
- Unit test coverage and testing framework requirements
- XML documentation / annotation requirements for new APIs
- Target branch and commit message format
- How to integrate these atomic abstractions with DotNext's existing concurrency/atomic design
Summary
This proposal introduces two sets of pure C# features ported from Rust's standard library and
crossbeam-queue, to extend DotNext's atomic operation and lock-free queue capabilities. I have completed the full implementation, and I want to confirm the adaptation requirements before submitting a PR.1. New Atomic Structure Encapsulation
Feature Overview
Add Rust-style atomic wrapper structures for common numeric types, including
int,long, as well as platform-sized typesAtomicIsize(nint) andAtomicUsize(nuint).This set of wrappers unifies scattered
VolatileandInterlockedAPI calls, and exposes explicit memory ordering parameters to control atomic memory behavior consistently following Rust atomic design.Core Capabilities
Interlockedatomic operations: read/write, exchange, compare-exchange, increment, decrement.And,Or,Xor.Relaxed,Acquire,Release,AcqRel,SeqCst.T Load(Ordering order)void Store(T value, Ordering order)Implementation Basis
Implemented based on standard .NET
UnsafeandInterlockedAPIs. The code can be refactored to match DotNext existing architecture and code style.Source: AtomicHelpers.cs
2. GC-Free Lock-Free Queue: SegQueue & ArrayQueue
Feature Overview
Ported Rust
crossbeam-queue'sSegQueueandArrayQueueto pure C#. The implementations work only withunmanagedtypes, suitable for GC-sensitive scenarios.Core Features
Implementation Basis
Full pure C# port implementation: crossbeam-queue C# Port
3. PR Adaptation Consultation & Next Steps
All features are fully implemented. I intend to submit a PR to integrate them into DotNext. I would like to clarify the project requirements for adaptation: