Soenneker.Atomics.ValueLocks
4.0.10
Prefix Reserved
dotnet add package Soenneker.Atomics.ValueLocks --version 4.0.10
NuGet\Install-Package Soenneker.Atomics.ValueLocks -Version 4.0.10
<PackageReference Include="Soenneker.Atomics.ValueLocks" Version="4.0.10" />
<PackageVersion Include="Soenneker.Atomics.ValueLocks" Version="4.0.10" />
<PackageReference Include="Soenneker.Atomics.ValueLocks" />
paket add Soenneker.Atomics.ValueLocks --version 4.0.10
#r "nuget: Soenneker.Atomics.ValueLocks, 4.0.10"
#:package Soenneker.Atomics.ValueLocks@4.0.10
#addin nuget:?package=Soenneker.Atomics.ValueLocks&version=4.0.10
#tool nuget:?package=Soenneker.Atomics.ValueLocks&version=4.0.10
Soenneker.Atomics.ValueLocks
Provides inline storage for a lazily created, atomically published Lock.
Install
dotnet add package Soenneker.Atomics.ValueLocks
Usage
Keep the mutable struct in a field and lock on the single published System.Threading.Lock:
using Soenneker.Atomics.ValueLocks;
public sealed class CacheIndex
{
private ValueAtomicLock _sync;
private readonly Dictionary<string, int> _values = new();
public void Set(string key, int value)
{
lock (_sync.Get())
{
_values[key] = value;
}
}
}
The default struct is ready to use and allocates its Lock only on first access. Racing callers can allocate temporary candidates, but all calls on the same struct storage return the one atomically published lock.
Never access this type through a property that returns it by value. Copying before initialization lets each copy publish a different lock, so callers would appear synchronized while entering separate critical sections.
ValueAtomicLock provides synchronous locking only. Use an async-compatible mutex when the protected operation must await.
What you get
ValueAtomicLock— Provides inline storage for a lazily created, atomically publishedLock.
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
ValueAtomicLock.IsValueCreated |
Gets a value indicating whether the lock has been created. | Gets a value indicating whether the lock has been created. |
ValueAtomicLock.Value |
Gets the single published lock, creating it if necessary. | Gets the single published lock, creating it if necessary. |
ValueAtomicLock.Get() |
Gets the single published lock, creating and atomically publishing it when uninitialized. | The requested lock. |
Important behavior
ValueAtomicLock: The default value is ready to use and does not allocate untilGetis first called. Concurrent callers may create temporary candidates, but every caller receives the single published lock. This is a mutablestructintended for use as a private field. Avoid copying it before initialization because each copy can publish a different lock and therefore establish a different lock domain.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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. |
-
net10.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (2)
Showing the top 2 NuGet packages that depend on Soenneker.Atomics.ValueLocks:
| Package | Downloads |
|---|---|
|
Soenneker.Atomics.ValueLazys
Thread-safe lazy initialization without Lazy wrapper allocations. |
|
|
Soenneker.Atomics.ValueNullableLazys
Allocation-conscious lazy initialization that correctly caches null values. |
GitHub repositories
This package is not used by any popular GitHub repositories.