Record lock-free guard acquisitions and report whether a later attempt was blocked.

Atomic Guard Coordination Report

atomic_guard_coordination_report.cpp
#include <atomic>
#include <iostream>
#include <string>

int main() {
    int attempts = ;
    std::atomic<int> permit{0};
    int acquired = 0;
    int blocked = 0;

    for (int i = 0; i < attempts; ++i) {
        int expected = 0;
        if (permit.compare_exchange_strong(expected, 1)) {
            acquired += 1;
        } else {
            blocked += 1;
        }
    }

    std::string status;
    if (acquired == 0) {
        status = "idle";
    } else if (blocked > 0) {
        status = "blocked";
    } else {
        status = "guarded";
    }

    std::cout << "attempts=" << attempts
              << " acquired=" << acquired
              << " blocked=" << blocked
              << " " << status << std::endl;
    return 0;
}
#include <atomic>
#include <iostream>
#include <string>

int main() {
    int attempts = ;
    std::atomic<int> permit{0};
    int acquired = 0;
    int blocked = 0;

    for (int i = 0; i < attempts; ++i) {
        int expected = 0;
        if (permit.compare_exchange_strong(expected, 1)) {
            acquired += 1;
        } else {
            blocked += 1;
        }
    }

    std::string status;
    if (acquired == 0) {
        status = "idle";
    } else if (blocked > 0) {
        status = "blocked";
    } else {
        status = "guarded";
    }

    std::cout << "attempts=" << attempts
              << " acquired=" << acquired
              << " blocked=" << blocked
              << " " << status << std::endl;
    return 0;
}
#include <atomic>
#include <iostream>
#include <string>

int main() {
    int attempts = ;
    std::atomic<int> permit{0};
    int acquired = 0;
    int blocked = 0;

    for (int i = 0; i < attempts; ++i) {
        int expected = 0;
        if (permit.compare_exchange_strong(expected, 1)) {
            acquired += 1;
        } else {
            blocked += 1;
        }
    }

    std::string status;
    if (acquired == 0) {
        status = "idle";
    } else if (blocked > 0) {
        status = "blocked";
    } else {
        status = "guarded";
    }

    std::cout << "attempts=" << attempts
              << " acquired=" << acquired
              << " blocked=" << blocked
              << " " << status << std::endl;
    return 0;
}
compare-and-exchange acquire A coordination report records nonblocking acquire attempts. A `std::atomic<int>` permit starts at zero, and `compare_exchange_strong` swaps it to one only when it still reads zero, so the first attempt takes the permit and returns true while a later attempt in the same run reads one and returns false. The exchange never blocks and never spawns a thread, so the report stays deterministic: the status line summarizes whether the guard stayed idle, guarded a single holder, or blocked a later acquire.