Compze.Threading.Interprocess 0.9.0-alpha

Prefix Reserved
This is a prerelease version of Compze.Threading.Interprocess.
There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package Compze.Threading.Interprocess --version 0.9.0-alpha
                    
NuGet\Install-Package Compze.Threading.Interprocess -Version 0.9.0-alpha
                    
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="Compze.Threading.Interprocess" Version="0.9.0-alpha" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Compze.Threading.Interprocess" Version="0.9.0-alpha" />
                    
Directory.Packages.props
<PackageReference Include="Compze.Threading.Interprocess" />
                    
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 Compze.Threading.Interprocess --version 0.9.0-alpha
                    
#r "nuget: Compze.Threading.Interprocess, 0.9.0-alpha"
                    
#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 Compze.Threading.Interprocess@0.9.0-alpha
                    
#: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=Compze.Threading.Interprocess&version=0.9.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Compze.Threading.Interprocess&version=0.9.0-alpha&prerelease
                    
Install as a Cake Tool

Compze.Threading.Interprocess

Cross-process synchronization for Compze.Threading. It brings the same pit-of-success locking model — impossible to forget to lock, automatic deadlock diagnosis with dual stack traces — across process boundaries, backed by the operating system's named mutexes.

Extracted from Compze.Threading 0.7.0-alpha so the cross-process primitives can version independently of the in-process ones. It depends on Compze.Threading for the shared ICriticalSection / IAwaitableCriticalSection abstractions that both the in-process and cross-process implementations satisfy — so an IMutex is an ICriticalSection and an IAwaitableMutex is an IAwaitableCriticalSection, interchangeable with their in-process counterparts wherever the abstraction is what matters.

What it adds

IMutex — a cross-process lock that diagnoses its own deadlocks

A named system Mutex wrapped so it behaves like the rest of Compze.Threading: Global (visible across all login sessions) and Local (one session) variants, cancellation-token support, abandoned-mutex recovery, and the same timeout-and-dual-stack-trace deadlock diagnostics as the in-process IMonitor.

IAwaitableMutex — Monitor.Wait semantics across processes

The full condition-wait model — TakeUpdateLockWhen(condition), TakeReadLockWhen(condition), and the TryTake* variants — working across processes. It releases every nesting level of the lock while waiting and reacquires on signal, mirroring Monitor.Wait exactly. As far as we know, no other .NET library exposes the full Monitor/condition-wait model over a cross-process mutex.

using var mutex = IAwaitableMutex.Global("MyResource", directory);
using(mutex.TakeUpdateLockWhen(() => ResourceIsReady()))
{
    // Exclusive across every process on the machine; the wait released the lock
    // for other processes and reacquired it once the condition held.
}

The async condition waits — TryAwaitAsync, ReadWhenAsync, UpdateWhenAsync, TryUpdateWhenAsync — work across processes too, and hold no thread while they wait: between polls of the signal (see ISignalPollingPolicy below) nothing waits but a timer.

IProcessLock — a lock between processes that any thread can release

A lock on an IMutex can only be released by the thread that took it, so async code can't hold it across an await, nor can an xUnit fixture take it as it is created and release it as it is disposed. An IProcessLock belongs to its holder instead: disposing the IProcessLockHold that taking it returns releases it, from whichever thread. The operating system releases it when the holder's process dies, so a crashed or killed process never leaves it held.

var sandboxTurn = IProcessLock.New("sandbox-turn", directory);
using(await sandboxTurn.TakeAsync("running the sandbox specifications", WaitTimeout.Minutes(20)))
{
    // Every other process taking "sandbox-turn" in this directory waits until the hold is disposed.
}

The wait is a WaitTimeout, not a LockTimeout: a holder may rightly hold it for minutes, so a long wait is no sign of a deadlock. A Take that gives up says what the lock is held for, by which process, and since when; TryTake(purpose, WaitTimeout.Zero) answers at once. The lock is a file in the directory, which its holder keeps open, and a wait tries it every 50 milliseconds: it isn't fair, nor reentrant.

IProcessSemaphore — a counting semaphore between processes that a dead holder can't leave held

Of its units, such as sandboxes that may run at once, each is held by one holder at a time, whichever process it is in. A take of several units takes them all or none, and takes are served in the order they came, so a take of many units isn't starved by takes of few. Each unit is held as an IProcessLock is, so the operating system releases the units of a holder whose process dies, and a take whose process dies waiting gives up its place. Windows' named Semaphore has no holders: units a dead process held are gone until it is made anew.

var sandboxes = IProcessSemaphore.New("sandboxes", units: 16, directory);
using(await sandboxes.TakeAsync(3, "running the scenario's three sandboxes", WaitTimeout.Minutes(20)))
{
    // At most 16 sandboxes run at once, whichever processes on the machine run them.
}

A Take that gives up says who holds the units and who waits ahead: how many units, what for, which process, and since when. DescribeHoldersAndWaiters() says the same while a take waits, which giving up and taking again would lose its place in the order.

IProcessShared<T> / IAwaitableProcessShared<T>

Pair a shared object with a cross-process mutex to coordinate access to an external resource — a file, a port, a database — across processes. Each process has its own object: for an object the processes really share, see IInterprocessObject<T> below.

IInterprocessObject<T> — an object shared between processes, in a single line of code

An IAwaitableProcessShared<T> whose object every process shares: kept in a memory-mapped file, so a change one process makes is visible to all the others at once, and the object survives the processes and reboots.

  • Atomic updates: every read and update holds the object's cross-process mutex, so a read-modify-write is safe.
  • Waits for conditions: the same condition waits as IAwaitableMutex, with the object loaded for each evaluation of the condition and saved after an update.
  • Recovery from corruption: CorruptionAction says whether an object that can't be read is replaced with its default or left as it is for you to look at. Either way the access that found it throws, saying what happened.
  • Pluggable serialization: JSON with IInterprocessObjectSerializer.Json<T>(), MemoryPack with the Compze.Threading.Interprocess.MemoryPack plugin, or a serializer of your own.
using var visits = IInterprocessObject.NewGlobal("visits", IInterprocessObjectSerializer.Json<Visits>(), () => new Visits(),
                                                 CorruptionAction.ReplaceContentWithDefaultAndThrow, maxBytes: 4 * 1024, directory);
visits.Update(it => it.Count++);

It came here from Compze.InterprocessObject, which is retired: its types are in the namespace Compze.Threading.Interprocess.ResourceAccess now.

ISignalPollingPolicy — the latency-versus-power knob

Awaiting a cross-process condition polls a memory-mapped change counter, because .NET has no portable cross-process kernel signal. Each poll wakes the CPU, and frequent wakeups keep it out of its deep low-power idle states — a real battery cost on laptops. ISignalPollingPolicy decides the poll cadence; the default backs off adaptively (eager at first, then stretching toward a 50 ms cap), and you can supply your own.

Product Compatible and additional computed target framework versions.
.NET net11.0 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (5)

Showing the top 5 NuGet packages that depend on Compze.Threading.Interprocess:

Package Downloads
Compze.Tessaging

Messaging infrastructure for the Compze framework including command, query, and event handling.

Compze.Sql.Sqlite

Discontinued: this is its last version. Compze no longer supports SQLite: it runs one writer at a time, so it could never be a fully supported persistence layer. Use Compze.Sql.MicrosoftSql for SQL Server, Compze.Sql.PostgreSql for PostgreSQL or Compze.Sql.MySql for MySQL. SQLite support for the Compze framework: declares the SQLite domain database that Compze endpoints join. Also carries the SQLite plumbing the Compze.*.Sqlite feature backends share.

Compze.Hosting

Endpoint hosting for the Compze framework — endpoints, endpoint hosts, and the builder that capabilities such as the Tessaging and Typermedia pipelines plug into.

Compze.Teventive.MemoryImageStateStore

A memory image of taggregates: every taggregate held in memory for the container's life, rebuilt at its start from a snapshot of each, which JSON files, or a database's tables, keep. A taggregate store that keeps taggregates as their state, not their history.

Compze.Internals.Testing

For Compze internal use only. Do not take a dependency on this package

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.20.0-alpha 0 12/5/2026
0.19.0-alpha 0 12/5/2026
0.18.0-alpha 0 12/5/2026
0.17.1-alpha 0 12/5/2026
0.17.0-alpha 7 12/5/2026
0.16.4-alpha 76 12/5/2026
0.16.3-alpha 203 12/5/2026
0.16.2-alpha 184 12/4/2026
0.16.1-alpha 78 12/4/2026
0.16.0-alpha 314 12/3/2026
0.15.0-alpha 90 12/3/2026
0.14.0-alpha 89 12/2/2026
0.13.0-alpha 277 12/2/2026
0.12.0-alpha 383 11/29/2026
0.11.3-alpha 153 11/28/2026
0.11.2-alpha 143 11/28/2026
0.11.1-alpha 243 11/28/2026
0.11.0-alpha 122 11/27/2026
0.10.0-alpha 107 11/26/2026
0.9.0-alpha 131 11/26/2026
Loading failed

- **`IProcessSemaphore`: a counting semaphore between processes, whose units belong to their holders.** `IProcessSemaphore.New(name, units, directory)` makes it, and every process that makes one of the same name in the same directory has the same semaphore. `TryTake`, `Take`, `TryTakeAsync` and `TakeAsync` take a number of its units for a purpose, waiting at most a `WaitTimeout`, and return an `IProcessSemaphoreHold`, which any thread may dispose to release them. `DescribeHoldersAndWaiters` says who holds units and who waits for them, for a holder that tells of a long wait.
 - **A take of several units takes them all, or none,** so two holders never each hold a part of what the other needs, and **takes are served in the order they came,** so a take of many units isn't starved by takes of few: a take waits while an earlier one waits, even when there are units enough for it.
 - **The operating system releases the units of a holder whose process dies, and a take whose process dies waiting gives up its place,** so a crashed or killed process never leaves units held, nor the takes after it waiting. Windows' named `Semaphore` has no holders: units a dead process held are gone until it is made anew.
 - **A `Take` that gives up throws a `TimeoutException` saying who holds the units and who waits ahead:** how many units, what for, which process, and since when.
 - **Each unit is a lock file, held as an `IProcessLock`'s is,** and the waiting takes are in a queue in an `IInterprocessObject<T>` beside them. A release ends the waits at once; the death of a holder or of a waiting take tells nothing, so a waiting take also looks every second.
 - **All who use a semaphore at once use the same number of units:** one made with another number takes units only once none are held or waited for, and from then on the semaphore has that number; else its take throws an `InvalidOperationException`.
- **`IInterprocessObject<T>`, an object shared between processes, is here now, in the namespace `Compze.Threading.Interprocess.ResourceAccess`, beside the `IAwaitableProcessShared<T>` it extends.** It came from Compze.InterprocessObject, which is retired: it has no versions after 0.10.0-alpha. With it came `IInterprocessObject` (its factory), `IInterprocessObjectSerializer<T>` and `IInterprocessObjectSerializer` (the factory of its JSON serializer), and `CorruptionAction`, unchanged but for their namespace, which was `Compze.InterprocessObject`. To upgrade, replace a reference to Compze.InterprocessObject with one to this package, and `using Compze.InterprocessObject;` with `using Compze.Threading.Interprocess.ResourceAccess;`. The package now depends on Compze.Internals.SystemCE, as Compze.InterprocessObject did.