Soenneker.Atomics.ValueBools
4.0.38
Prefix Reserved
dotnet add package Soenneker.Atomics.ValueBools --version 4.0.38
NuGet\Install-Package Soenneker.Atomics.ValueBools -Version 4.0.38
<PackageReference Include="Soenneker.Atomics.ValueBools" Version="4.0.38" />
<PackageVersion Include="Soenneker.Atomics.ValueBools" Version="4.0.38" />
<PackageReference Include="Soenneker.Atomics.ValueBools" />
paket add Soenneker.Atomics.ValueBools --version 4.0.38
#r "nuget: Soenneker.Atomics.ValueBools, 4.0.38"
#:package Soenneker.Atomics.ValueBools@4.0.38
#addin nuget:?package=Soenneker.Atomics.ValueBools&version=4.0.38
#tool nuget:?package=Soenneker.Atomics.ValueBools&version=4.0.38
Soenneker.Atomics.ValueBools
A lightweight, allocation-free atomic boolean struct implemented on top of an inline ValueAtomicInt. This type provides atomic read, write, and compare-and-set semantics for boolean values using a single integer backing field (0 = false, 1 = true).
Install
dotnet add package Soenneker.Atomics.ValueBools
Usage
Keep the mutable struct in a field so every operation addresses the same storage:
using Soenneker.Atomics.ValueBools;
public sealed class Worker
{
private ValueAtomicBool _stopping;
public bool RequestStop() => _stopping.TrySetTrue();
public bool IsStopping => _stopping.Read();
}
Do not expose it through a value-returning property, pass it by value, or store it in an API that copies structs. A copy contains independent atomic state; changes to the copy do not update the original field. Use the reference-type AtomicBool package when the state itself must be passed between objects.
Individual operations are atomic, but a read followed by a write is not one conditional operation. Use CompareAndSet, TrySetTrue, or TrySetFalse for state transitions.
What you get
ValueAtomicBool— A lightweight, allocation-free atomic boolean struct implemented on top of an inlineValueAtomicInt. This type provides atomic read, write, and compare-and-set semantics for boolean values using a single integer backing field (0 = false, 1 = true).
API at a glance
| API | What it does | Result / important behavior |
|---|---|---|
ValueAtomicBool.Read() |
Reads the current value of the atomic boolean. | true if the current value is true; otherwise false. |
ValueAtomicBool.Write(value) |
Writes a new value to the atomic boolean. | This operation performs an atomic write with release semantics. |
ValueAtomicBool.Exchange(value) |
Atomically replaces the current value with value and returns the previous value. |
The value that was stored prior to the exchange. |
ValueAtomicBool.CompareAndSet(expected, newValue) |
Atomically sets the value to newValue if the current value equals expected. |
true if the value was updated; otherwise false. |
ValueAtomicBool.Value |
Gets or sets the current value of the atomic boolean. | The getter performs an atomic read with acquire semantics. The setter performs an atomic write with release semantics. |
ValueAtomicBool.TrySetTrue() |
Attempts to atomically transition the value from false to true. |
true if the value was updated; false if it was already true. |
ValueAtomicBool.TrySetFalse() |
Attempts to atomically transition the value from true to false. |
true if the value was updated; false if it was already false. |
ValueAtomicBool.ToString() |
Returns a string representation of the current value. | Returns string. |
Important behavior
ValueAtomicBool: Reads establish acquire semantics and writes establish release semantics, making this type suitable for visibility signaling and safe publication between threads. This is a mutablestructintended for use as a private field or inline synchronization primitive. Avoid copying this type, returning it from properties, or using it through interfaces, as doing so will create independent copies of the atomic state.ValueAtomicBool.Write(value): This operation performs an atomic write with release semantics.ValueAtomicBool.Value: The getter performs an atomic read with acquire semantics. The setter performs an atomic write with release semantics.ValueAtomicBool.TrySetTrue(): This method performs a single compare-and-exchange operation and does not spin or retry.ValueAtomicBool.TrySetFalse(): This method performs a single compare-and-exchange operation and does not spin or retry.
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | 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
- Soenneker.Atomics.ValueInts (>= 4.0.26)
NuGet packages (16)
Showing the top 5 NuGet packages that depend on Soenneker.Atomics.ValueBools:
| Package | Downloads |
|---|---|
|
Soenneker.Utils.AsyncSingleton
An externally initializing singleton that uses double-check asynchronous locking, with optional async and sync disposal |
|
|
Soenneker.Utils.Logger
Builds cached Microsoft loggers backed by Serilog and exposes a shared runtime level switch. |
|
|
Serilog.Sinks.XUnit.Injectable
The injectable, xUnit test output sink for Serilog |
|
|
Soenneker.Dictionaries.SingletonKeys
An externally initializing singleton dictionary that uses double-check asynchronous locking, with optional async and sync disposal |
|
|
Soenneker.Redis.Lock
A utility library leveraging Redis that provides distributed locking |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 4.0.38 | 6,387 | 8/30/2026 |
| 4.0.37 | 1,438 | 8/29/2026 |
| 4.0.36 | 2,040 | 8/29/2026 |
| 4.0.35 | 357,577 | 7/28/2026 |
| 4.0.34 | 7,110 | 7/28/2026 |
| 4.0.33 | 179,005 | 7/16/2026 |
| 4.0.32 | 35,232 | 7/16/2026 |
| 4.0.31 | 243,028 | 6/19/2026 |
| 4.0.30 | 22,275 | 6/18/2026 |
| 4.0.29 | 238,173 | 6/5/2026 |
| 4.0.28 | 632 | 6/5/2026 |
| 4.0.27 | 120 | 6/5/2026 |
| 4.0.26 | 321,283 | 4/22/2026 |
| 4.0.25 | 7,370 | 4/22/2026 |
| 4.0.23 | 285,466 | 3/12/2026 |
| 4.0.22 | 7,117 | 3/12/2026 |
| 4.0.21 | 2,078 | 3/12/2026 |
| 4.0.20 | 1,201 | 3/12/2026 |
| 4.0.19 | 5,722 | 3/12/2026 |
| 4.0.18 | 79,099 | 3/11/2026 |
Update dependency Soenneker.Atomics.ValueInts to 4.0.26 (#68)