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
                    
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="Soenneker.Atomics.ValueLocks" Version="4.0.10" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Soenneker.Atomics.ValueLocks" Version="4.0.10" />
                    
Directory.Packages.props
<PackageReference Include="Soenneker.Atomics.ValueLocks" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Soenneker.Atomics.ValueLocks --version 4.0.10
                    
#r "nuget: Soenneker.Atomics.ValueLocks, 4.0.10"
                    
#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.
#:package Soenneker.Atomics.ValueLocks@4.0.10
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Soenneker.Atomics.ValueLocks&version=4.0.10
                    
Install as a Cake Addin
#tool nuget:?package=Soenneker.Atomics.ValueLocks&version=4.0.10
                    
Install as a Cake Tool

alternate text is missing from this package README image alternate text is missing from this package README image alternate text is missing from this package README image

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 published Lock.

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 until Get is first called. Concurrent callers may create temporary candidates, but every caller receives the single published lock. This is a mutable struct intended 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 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. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.
  • 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.

Version Downloads Last Updated
4.0.10 566 9/1/2026
4.0.9 4,316 9/1/2026
4.0.8 411 9/1/2026
4.0.6 8,107 8/29/2026
4.0.5 59 8/29/2026
4.0.4 59 8/29/2026
4.0.3 61,633 8/26/2026
4.0.2 171 8/26/2026