Deterministic allocation and freeing of scarce resources