static L<CriticalAction> beginCriticalAction_inFlight = synchroList();

sclass CriticalAction is AutoCloseable {
  S description;
  
  *() {}
  *(S *description) {}
  
  public void done aka close() {
    beginCriticalAction_inFlight.remove(this);
  }
}

static CriticalAction beginCriticalAction(S description) {
  ping();
  CriticalAction c = new CriticalAction(description);
  beginCriticalAction_inFlight.add(c);
  ret c;
}

svoid cleanMeUp_beginCriticalAction() {
  int n = 0;
  while (nempty(beginCriticalAction_inFlight)) {
    int m = l(beginCriticalAction_inFlight);
    if (m != n) {
      n = m;
      pcall {
        print("Waiting for " + n2(n, "critical actions") + ": " + join(", ", collect(beginCriticalAction_inFlight, "description"));
      }
    }
    sleepInCleanUp(10);
  }
}