Skip to main content

try_acquire

Function try_acquire 

Source
pub fn try_acquire(
    gauge: &Arc<Atomic<usize>>,
    max_concurrent: usize,
) -> Option<ConcurrencyGuard>
Expand description

Fail-closed concurrency check-and-acquire (resource bound: “a max concurrent subagents… cap, fail-closed”). Atomic compare-exchange loop (not a check-then-increment race, which would let two racing spawns both pass a check against the same stale count) — None when max_concurrent subagents are already in flight anywhere in this spawn tree (the gauge is a single Arc shared root-to-leaf, per crate::agent::Agent’s doc comment on its own concurrency-gauge field), Some(guard) otherwise, with the slot already counted.