Concurrency Coordination Reports
Semaphore Guard Coordination Report
Record nonblocking guard acquisitions and report whether a later attempt was blocked.
Semaphore Guard Coordination Report
SemaphoreGuardCoordinationReport.cs
using System;
using System.Threading;
class Program
{
static void Main()
{
int holds = ;
var guard = new SemaphoreSlim(1, 1);
int acquired = 0;
int blocked = 0;
for (int i = 0; i < holds; i++)
{
if (guard.Wait(0))
{
acquired++;
}
else
{
blocked++;
}
}
string status;
if (acquired == 0)
{
status = "idle";
}
else if (blocked > 0)
{
status = "blocked";
}
else
{
status = "guarded";
}
Console.WriteLine("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status);
}
}
using System;
using System.Threading;
class Program
{
static void Main()
{
int holds = ;
var guard = new SemaphoreSlim(1, 1);
int acquired = 0;
int blocked = 0;
for (int i = 0; i < holds; i++)
{
if (guard.Wait(0))
{
acquired++;
}
else
{
blocked++;
}
}
string status;
if (acquired == 0)
{
status = "idle";
}
else if (blocked > 0)
{
status = "blocked";
}
else
{
status = "guarded";
}
Console.WriteLine("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status);
}
}
using System;
using System.Threading;
class Program
{
static void Main()
{
int holds = ;
var guard = new SemaphoreSlim(1, 1);
int acquired = 0;
int blocked = 0;
for (int i = 0; i < holds; i++)
{
if (guard.Wait(0))
{
acquired++;
}
else
{
blocked++;
}
}
string status;
if (acquired == 0)
{
status = "idle";
}
else if (blocked > 0)
{
status = "blocked";
}
else
{
status = "guarded";
}
Console.WriteLine("holds=" + holds + " acquired=" + acquired + " blocked=" + blocked + " " + status);
}
}
nonblocking acquire
A coordination report records nonblocking acquire attempts. A `SemaphoreSlim` created with one permit acts as an exclusive guard, and `Wait(0)` returns true when it takes the permit and false when the permit is already held, so it never blocks. The first acquire takes the only permit, so a later attempt in the same run is reported as blocked and the status line summarizes whether the section stayed idle, guarded, or blocked a later acquire.