Open.Threading.ReadWrite
2.0.3
dotnet add package Open.Threading.ReadWrite --version 2.0.3
NuGet\Install-Package Open.Threading.ReadWrite -Version 2.0.3
<PackageReference Include="Open.Threading.ReadWrite" Version="2.0.3" />
paket add Open.Threading.ReadWrite --version 2.0.3
#r "nuget: Open.Threading.ReadWrite, 2.0.3"
// Install Open.Threading.ReadWrite as a Cake Addin #addin nuget:?package=Open.Threading.ReadWrite&version=2.0.3 // Install Open.Threading.ReadWrite as a Cake Tool #tool nuget:?package=Open.Threading.ReadWrite&version=2.0.3
Open.Threading.ReadWrite
Useful set of extensions and classes for simplifying and optimizing read-write synchronization with ReaderWriterLockSlim
.
Purpose
There are very common but tedious patterns to follow when utilizing a ReaderWriterLockSlim
. Some of the more complex but useful patterns involve reading (with or without a read lock) and then if a condition is met, acquiring a write lock before proceeding.
This extension library removes the tediousness of properly acquiring and releasing various locks and provides easy access to timeout values if needed.
Basics
Read
rwLockSlim.Read(() =>
{
/* do work inside a read lock */
});
using(rwLockSlim.ReadLock())
{
/* do work inside a read lock */
}
int result = rwLockSlim.Read(() =>
{
int i;
/* produce a result inside read lock */
return i;
});
Write
rwLockSlim.Write(() =>
{
/* do work inside a read lock */
});
using(rwLockSlim.WriteLock())
{
/* do work inside a write lock */
}
int result = rwLockSlim.Write(() =>
{
int i;
/* produce a result inside write lock */
return i;
});
Upgradable Read
using(rwLockSlim.UpgradableReadLock())
{
/* do work inside an upgradable read lock */
if(condition)
{
using(rwLockSlim.WriteLock())
{
/* upgraded to a write lock */
}
}
}
With Timeouts
These throw a TimeoutException
if a lock cannot be acquired within the time specified.
Read
rwLockSlim.Read(1000 /* ms */, () =>
{
/* do work inside a read lock */
});
or
using(rwLockSlim.ReadLock(1000)) // ms
{
/* do work inside a read lock */
}
Write
rwLockSlim.Write(1000 /* ms */, () =>
{
/* do work inside a write lock */
});
or
using(rwLockSlim.WriteLock(1000)) // ms
{
/* do work inside a write lock */
}
Advanced Examples
WriteConditional
This example demonstrates how to properly query a value before writing with a 1 second timeout.
var actionWasInvoked = rwLockSlim.WriteConditional(1000 /* ms */,
() => /* condition that is queried inside an upgradable read lock */,
() => /* do work inside a write lock */);
ReadWriteConditional
This more advanced example optimizes the process of reading and then writing by first testing the condition within a read lock before attempting with an upgradable read lock.
int result = 0;
bool actionWasInvoked = rwLockSlim.ReadWriteConditional(ref result,
isUpgraded => /* condition that is first queried inside a read lock */,
() =>
{
int i;
/* do work inside a write lock */
return i;
});
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET | net5.0 was computed. net5.0-windows was computed. net6.0 was computed. 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 was computed. 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 was computed. 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. |
.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 is compatible. |
.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.
-
.NETStandard 2.1
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on Open.Threading.ReadWrite:
Package | Downloads |
---|---|
Open.Threading.ReadWriteHelper
A utility for read-write synchronizing by context. Useful for synchronizing collections that are not inherently thread-safe. Reference to Open.Threading.ReadWrite exposes extensions for ReaderWriterLockSlim. Part of the "Open" set of libraries. |
|
ObservableValue
A class representing a value that when updated (posted) signals changes to observers. Will post current value (if initialized) when subscribing. Synchronized to ensure ordering. Compatible with IObservable<T> and System.Reactive. |
|
LiveStreamingServerNet.StreamProcessor
This package provides the capability to transmux RTMP streams into HLS format, and integrates with FFmpeg for stream processing. |
GitHub repositories (1)
Showing the top 1 popular GitHub repositories that depend on Open.Threading.ReadWrite:
Repository | Stars |
---|---|
josephnhtam/live-streaming-server-net
A .NET implementation of RTMP live streaming server, supporting HTTP-FLV, WebSocket-FLV, HLS, Kubernetes, cloud storage services integration and more.
|
Version | Downloads | Last updated |
---|---|---|
2.0.3 | 15,702 | 3/24/2022 |
2.0.2 | 38,648 | 3/22/2022 |
2.0.1 | 1,447 | 3/22/2022 |
2.0.0 | 683 | 3/22/2022 |
2.0.0-preview3 | 878 | 3/21/2022 |
2.0.0-preview2 | 938 | 3/21/2022 |
2.0.0-preview1 | 422 | 3/19/2022 |
1.4.8 | 3,927 | 9/29/2021 |
1.4.5 | 1,581 | 7/11/2021 |
1.4.4 | 892 | 7/11/2021 |
1.4.3 | 1,770 | 7/7/2021 |
1.4.0 | 52,109 | 7/17/2020 |
1.3.3 | 16,546 | 1/4/2020 |
1.3.2 | 20,004 | 7/4/2019 |
1.1.2 | 7,918 | 7/18/2018 |