Record permit draws against a fixed budget and report whether demand was capped.

Semaphore Budget Coordination Report

SemaphoreBudgetCoordinationReport.cs
using System;
using System.Threading;

class Program
{
    static void Main()
    {
        int requests = ;
        int capacity = 2;
        var permits = new SemaphoreSlim(capacity, capacity);
        int granted = 0;
        int denied = 0;

        for (int i = 0; i < requests; i++)
        {
            if (permits.Wait(0))
            {
                granted++;
            }
            else
            {
                denied++;
            }
        }

        string status;
        if (denied > 0)
        {
            status = "capped";
        }
        else if (granted == capacity)
        {
            status = "spent";
        }
        else
        {
            status = "spare";
        }

        Console.WriteLine("requests=" + requests + " granted=" + granted + " denied=" + denied + " " + status);
    }
}
using System;
using System.Threading;

class Program
{
    static void Main()
    {
        int requests = ;
        int capacity = 2;
        var permits = new SemaphoreSlim(capacity, capacity);
        int granted = 0;
        int denied = 0;

        for (int i = 0; i < requests; i++)
        {
            if (permits.Wait(0))
            {
                granted++;
            }
            else
            {
                denied++;
            }
        }

        string status;
        if (denied > 0)
        {
            status = "capped";
        }
        else if (granted == capacity)
        {
            status = "spent";
        }
        else
        {
            status = "spare";
        }

        Console.WriteLine("requests=" + requests + " granted=" + granted + " denied=" + denied + " " + status);
    }
}
using System;
using System.Threading;

class Program
{
    static void Main()
    {
        int requests = ;
        int capacity = 2;
        var permits = new SemaphoreSlim(capacity, capacity);
        int granted = 0;
        int denied = 0;

        for (int i = 0; i < requests; i++)
        {
            if (permits.Wait(0))
            {
                granted++;
            }
            else
            {
                denied++;
            }
        }

        string status;
        if (denied > 0)
        {
            status = "capped";
        }
        else if (granted == capacity)
        {
            status = "spent";
        }
        else
        {
            status = "spare";
        }

        Console.WriteLine("requests=" + requests + " granted=" + granted + " denied=" + denied + " " + status);
    }
}
bounded budget A coordination report can record draws against a bounded budget. A `SemaphoreSlim` created with a fixed capacity grants permits while they last, and `Wait(0)` returns false once the budget is spent, so over-demand is denied rather than blocked. When demand stays under capacity the budget keeps spare permits, when demand exactly matches capacity the budget is spent, and when demand exceeds capacity the extra draws are denied and capped. The status line summarizes whether the budget stayed spare, was spent, or capped demand.