interop peers: hold-lock mode in the C# peer and the Rust example

Each holds <file>.lock by its own runtime's protocol (share-none open; fs2 exclusive),
prints {"held":true}, sleeps --ms, releases.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Meta Vens 2026-10-20 14:50:19 +02:00
commit 3cd9880c04
2 changed files with 36 additions and 2 deletions

View file

@ -16,7 +16,7 @@ static async Task<int> ProgramMainAsync(string[] args)
{
if (args.Length == 0)
{
throw new InvalidOperationException("Expected mode: write | read | write-routed <catalog.cc> <run.cc>");
throw new InvalidOperationException("Expected mode: write | read | hold-lock | write-routed <catalog.cc> <run.cc>");
}
var mode = args[0];
@ -38,6 +38,9 @@ static async Task<int> ProgramMainAsync(string[] args)
case "read":
await ReadAsync(file);
return 0;
case "hold-lock":
HoldLock(file, int.Parse(RequireArg(options, "ms"), CultureInfo.InvariantCulture));
return 0;
default:
throw new InvalidOperationException($"Unknown mode {mode}.");
}
@ -49,6 +52,20 @@ static async Task<int> ProgramMainAsync(string[] args)
}
}
// Holds the store lock exactly as CultCache.AcquireLock opens it, for --ms, then releases it.
static void HoldLock(string file, int milliseconds)
{
using var held = new System.IO.FileStream(
file + ".lock",
System.IO.FileMode.OpenOrCreate,
System.IO.FileAccess.ReadWrite,
System.IO.FileShare.None,
bufferSize: 1);
Console.WriteLine("{\"held\":true}");
Console.Out.Flush();
System.Threading.Thread.Sleep(milliseconds);
}
static async Task WriteAsync(string file, string runtimeId)
{
var cache = BuildCache(file);