Compze.Threading.Interprocess
0.16.1-alpha
Prefix Reserved
See the version list below for details.
dotnet add package Compze.Threading.Interprocess --version 0.16.1-alpha
NuGet\Install-Package Compze.Threading.Interprocess -Version 0.16.1-alpha
<PackageReference Include="Compze.Threading.Interprocess" Version="0.16.1-alpha" />
<PackageVersion Include="Compze.Threading.Interprocess" Version="0.16.1-alpha" />
<PackageReference Include="Compze.Threading.Interprocess" />
paket add Compze.Threading.Interprocess --version 0.16.1-alpha
#r "nuget: Compze.Threading.Interprocess, 0.16.1-alpha"
#:package Compze.Threading.Interprocess@0.16.1-alpha
#addin nuget:?package=Compze.Threading.Interprocess&version=0.16.1-alpha&prerelease
#tool nuget:?package=Compze.Threading.Interprocess&version=0.16.1-alpha&prerelease
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:
InterprocessObjectDeserializationExceptionreports the file, inFilePath, and the cause. The bytes remain available to a compatible reader. Code that knows starting over is safe callsReplaceIfUnreadable(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 | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net11.0 is compatible. |
-
net11.0
- Compze.Contracts (>= 0.7.2)
- Compze.Internals.SystemCE (>= 0.18.1-internal)
- Compze.Threading (= 0.16.1-alpha)
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 |
- Cancelling a synchronous `IAwaitableMutex` condition wait lets a caller that entered without a lock leave while another thread or process still holds the mutex. A caller that entered with locks regains those levels before receiving cancellation.
- Restoring the caller's lock levels is bounded by `LockTimeout`. If restoration times out, `TakeLockTimeoutException` identifies that wait. If restoration is interrupted, `ThreadInterruptedException` propagates. In either case, the caller has lost its locks and can unwind the old scopes safely, even after a fresh acquisition.
- If the abandonment callback throws while `IMutex` is acquiring an abandoned mutex, the mutex is released and the original exception propagates.
- **Requires exact versions of the Compze packages whose internals it uses:** Compze.Threading 0.16.1-alpha (was 0.16.0-alpha). Upgrading to this version upgrades each package listed here to exactly that version, so their changelogs apply to this upgrade as well.