Compze.Threading.Interprocess 0.16.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.16.0-alpha
                    
NuGet\Install-Package Compze.Threading.Interprocess -Version 0.16.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.16.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.16.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.16.0-alpha
                    
#r "nuget: Compze.Threading.Interprocess, 0.16.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.16.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.16.0-alpha&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Compze.Threading.Interprocess&version=0.16.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 how a wait polls, 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.

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 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. The writer stages the new value beside the file and renames it into place. A killed writer leaves either complete value available to readers.
  • Directory access: grant the participating processes permission to create and replace files in the chosen directory. Set data access restrictions on that directory so they also cover staged values and replacement files. During an update there are two files, each reserving the configured capacity plus its four-byte header.
  • Waits for conditions: the same condition waits as IAwaitableMutex, with the object loaded for each evaluation of the condition and saved after an update.
  • Unreadable state: InterprocessObjectDeserializationException reports the file, in FilePath, and the cause. The bytes remain available to a compatible reader. Code that knows starting over is safe calls ReplaceIfUnreadable(value), which, under the mutex, writes the value only while the content can't be read, and keeps the unreadable bytes in a new file beside the object's, returning its path: no other process finds the object missing meanwhile. Processes that fail to read it at once can each call it: the first writes, and the others find its value, write nothing and get null. By hand: stop every process using the file, delete it, and restart them.
  • Pluggable serialization: JSON with IInterprocessObjectSerializer.Json<T>(), or a serializer of your own, such as one in MemoryPack's binary form.
using var visits = IInterprocessObject.NewGlobal("visits", IInterprocessObjectSerializer.Json<Visits>(), () => new Visits(),
                                                 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.

How a wait polls: signal latency against power

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. So a wait backs off: it polls eagerly at first, when a signal is most likely to come soon, then ever less often, until its polls are 50 ms apart.

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 (6)

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.DbPool

Empty databases on demand for integration testing etc. Supports SQL Server, MySql, PostgreSQL and SQLite

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.

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

- **Breaking: `IInterprocessObject<T>.Replace` is `ReplaceIfUnreadable`, which writes only while the content can't be read.** Two processes that both failed to read the object could both call `Replace`, and the second overwrote what the first had just written. Under the object's mutex, `ReplaceIfUnreadable` writes nothing and returns null when the content can be read, so null always means nothing was written; otherwise it keeps the unreadable bytes beside the object's file, as `Replace` did, writes the value and returns the kept file's path. A deleted object holds nothing unreadable: it writes nothing and returns null, where `Replace` wrote the value. To write over content that can be read, update the object.