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
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="Open.Threading.ReadWrite" Version="2.0.3" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Open.Threading.ReadWrite --version 2.0.3
#r "nuget: Open.Threading.ReadWrite, 2.0.3"
#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.
// 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.

GitHub license 100% code coverage NuGet

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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • .NETStandard 2.0

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages (4)

Showing the top 4 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.Rtmp

This package implements the RTMP protocol.

LiveStreamingServerNet.Flv

This package provides the ASP.NET Core middlewares to serve FLV via HTTP and WebSocket.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.0.3 3,750 3/24/2022
2.0.2 29,533 3/22/2022
2.0.1 1,350 3/22/2022
2.0.0 642 3/22/2022
2.0.0-preview3 805 3/21/2022
2.0.0-preview2 854 3/21/2022
2.0.0-preview1 389 3/19/2022
1.4.8 3,575 9/29/2021
1.4.5 1,511 7/11/2021
1.4.4 839 7/11/2021
1.4.3 1,679 7/7/2021
1.4.0 47,217 7/17/2020
1.3.3 16,184 1/4/2020
1.3.2 19,551 7/4/2019
1.1.2 7,644 7/18/2018