Turn the number of waiters behind a held guard into an enter, backoff, or page remediation action.

guard contention The waiter count behind a held guard is kept as a scalar, so the remediation action stays deterministic and never depends on atomic identity or scheduler timing.

Atomic Guard Remediation Report

waiters
atomic_guard_remediation_report.cpp
Replay: real traced execution (multi-file project)
#include <iostream>
#include <string>

int main() {
    int waiters = 0;
    const int guardLimit = 2;
    int acquired = 1;

    std::string action;
    if (waiters == 0) {
        action = "enter";
    } else if (waiters <= guardLimit) {
        action = "backoff";
    } else {
        action = "page";
    }

    std::cout << "waiters=" << waiters
              << " acquired=" << acquired
              << " " << action << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int waiters = 1;
    const int guardLimit = 2;
    int acquired = 1;

    std::string action;
    if (waiters == 0) {
        action = "enter";
    } else if (waiters <= guardLimit) {
        action = "backoff";
    } else {
        action = "page";
    }

    std::cout << "waiters=" << waiters
              << " acquired=" << acquired
              << " " << action << std::endl;
    return 0;
}
#include <iostream>
#include <string>

int main() {
    int waiters = 3;
    const int guardLimit = 2;
    int acquired = 1;

    std::string action;
    if (waiters == 0) {
        action = "enter";
    } else if (waiters <= guardLimit) {
        action = "backoff";
    } else {
        action = "page";
    }

    std::cout << "waiters=" << waiters
              << " acquired=" << acquired
              << " " << action << std::endl;
    return 0;
}
  1. waiters ← 0, guardLimit ← 2, acquired ← 1, action ← (empty)

    4int main() {5    int waiters→ 0 = 0; //@waiters=1, 36    const int guardLimit→ 2 = 2;7    int acquired→ 1 = 1;89    std::string action→ (empty);10    if (waiters == 0) {
  2. action ← enter

    9std::string action;10if (waiters0 == 0) {11    action→ enter = "enter";12} else if (waiters <= guardLimit) {
  3. std::cout << "waiters=" << waiters

    18    std::cout << "waiters=" << waiters019              << " acquired=" << acquired120              << " " << actionenter << std::endl;21    return 0;22}
    outputwaiters=0 acquired=1 enter
  1. waiters ← 1, guardLimit ← 2, acquired ← 1, action ← (empty)

    4int main() {5    int waiters→ 1 = 1;6    const int guardLimit→ 2 = 2;7    int acquired→ 1 = 1;89    std::string action→ (empty);10    if (waiters == 0) {
  2. action ← backoff

    11    action = "enter";12} else if (waiters1 <= guardLimit2) {13    action→ backoff = "backoff";14} else {
  3. std::cout << "waiters=" << waiters

    18    std::cout << "waiters=" << waiters119              << " acquired=" << acquired120              << " " << actionbackoff << std::endl;21    return 0;22}
    outputwaiters=1 acquired=1 backoff
  1. waiters ← 3, guardLimit ← 2, acquired ← 1, action ← (empty)

    4int main() {5    int waiters→ 3 = 3;6    const int guardLimit→ 2 = 2;7    int acquired→ 1 = 1;89    std::string action→ (empty);10    if (waiters == 0) {
  2. action ← page

    13    action = "backoff";14} else {15    action→ page = "page";16}
  3. std::cout << "waiters=" << waiters

    18    std::cout << "waiters=" << waiters319              << " acquired=" << acquired120              << " " << actionpage << std::endl;21    return 0;22}
    outputwaiters=3 acquired=1 page