AsyncReaderWriterLock 1.0.2
dotnet add package AsyncReaderWriterLock --version 1.0.2
NuGet\Install-Package AsyncReaderWriterLock -Version 1.0.2
<PackageReference Include="AsyncReaderWriterLock" Version="1.0.2" />
<PackageVersion Include="AsyncReaderWriterLock" Version="1.0.2" />
<PackageReference Include="AsyncReaderWriterLock" />
paket add AsyncReaderWriterLock --version 1.0.2
#r "nuget: AsyncReaderWriterLock, 1.0.2"
#:package AsyncReaderWriterLock@1.0.2
#addin nuget:?package=AsyncReaderWriterLock&version=1.0.2
#tool nuget:?package=AsyncReaderWriterLock&version=1.0.2
AsyncReaderWriterLock
A lightweight, cross-platform asynchronous reader‑writer lock for .NET with sync/async support, cancellation, and fair queuing.
dotnet add package AsyncReaderWriterLock
- Package: nuget.org/packages/AsyncReaderWriterLock
- Version: 1.0.2 | .NET 5+ | .NET Standard 2.0
- Developer: Lonewolf239
Features
| Feature | Details | |
|---|---|---|
| 📖 | Async reader‑writer lock | Multiple readers can hold the lock simultaneously; writers are exclusive. |
| 🔄 | Sync + async acquire | ReadLock/WriteLock and ReadLockAsync/WriteLockAsync for all scenarios. |
| ⏸️ | Cancellation support | Pending async acquires can be canceled via CancellationToken. |
| 🧵 | Fair FIFO queuing | Readers and writers are queued in order of arrival. |
| 🧩 | Lightweight | Single file, no external dependencies. |
| 🔧 | Cross‑platform | Supports .NET 5+, .NET 6-10, and .NET Standard 2.0 (including .NET Framework 4.6.2+). |
| 🧪 | Tested | Full unit test suite ensures correctness under concurrency. |
Quick Start
Acquiring a read lock
using AsyncLocks;
var rwLock = new AsyncReaderWriterLock();
using (var releaser = rwLock.ReadLock())
{
// Multiple threads can read concurrently
Console.WriteLine("Reading protected data...");
}
Acquiring a write lock
using (var releaser = rwLock.WriteLock())
{
// Only one writer at a time
Console.WriteLine("Writing exclusive data...");
}
Asynchronous usage
// Async read lock
using (var releaser = await rwLock.ReadLockAsync())
{
await Task.Delay(100);
Console.WriteLine("Async read lock acquired");
}
// Async write lock with cancellation
var cts = new CancellationTokenSource(500);
try
{
using (var releaser = await rwLock.WriteLockAsync(cts.Token))
{
Console.WriteLine("Async write lock acquired");
}
}
catch (OperationCanceledException)
{
Console.WriteLine("Lock acquisition was canceled");
}
Disposal
The lock implements IDisposable. Dispose it when no longer needed to release all waiting threads and free resources.
using var rwLock = new AsyncReaderWriterLock();
// ... use lock
Advanced Usage
Nesting locks
The lock does not support recursive acquisition. Attempting to acquire the same lock again from the same thread will result in a deadlock or SynchronizationLockException (for write→write or write→read). Always design your code to avoid recursive locking.
Fairness
The lock is fair: waiting threads are served in the order they requested the lock. This prevents writer starvation.
Manual release
The Releaser returned by ReadLock()/WriteLock() is a struct that releases the lock when disposed. You can store it and release later, but ensure proper disposal to avoid deadlocks.
API Reference
Full method reference — API.md
Contributing
We welcome contributions! Please see CONTRIBUTING.md for guidelines.
Philosophy
Simple, reliable, thread‑safe. AsyncReaderWriterLock provides just the synchronization primitive you need — nothing more, nothing less. The API is minimal but powerful, and the implementation is thoroughly tested to ensure correctness under all circumstances.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 is compatible. net5.0-windows was computed. net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 is compatible. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
| .NET Core | netcoreapp2.0 was computed. netcoreapp2.1 was computed. netcoreapp2.2 was computed. netcoreapp3.0 was computed. netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 is compatible. netstandard2.1 was computed. |
| .NET Framework | net461 was computed. net462 was computed. net463 was computed. net47 was computed. net471 was computed. net472 was computed. net48 was computed. net481 was computed. |
| MonoAndroid | monoandroid was computed. |
| MonoMac | monomac was computed. |
| MonoTouch | monotouch was computed. |
| Tizen | tizen40 was computed. tizen60 was computed. |
| Xamarin.iOS | xamarinios was computed. |
| Xamarin.Mac | xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos was computed. |
-
.NETStandard 2.0
- No dependencies.
-
net10.0
- No dependencies.
-
net5.0
- No dependencies.
-
net6.0
- No dependencies.
-
net7.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (1)
Showing the top 1 NuGet packages that depend on AsyncReaderWriterLock:
| Package | Downloads |
|---|---|
|
NeoIni
Modern, thread-safe INI configuration library for .NET 5+ with AES-256 encryption, checksum validation, hot reload, and source generators. Supports .NET Standard 2.0 for legacy environments. |
GitHub repositories
This package is not used by any popular GitHub repositories.