On 4/6/2026 10:24 AM, Bonita Montero wrote:
Here's the final benapohre - with an templated option for recursive
access.
[...]
fast path semaphores are fun:
Even in the post n case:
____________
void post_n(int n)
{
std::atomic_thread_fence(std::memory_order_release);
int old_count = m_count.fetch_add(n, std::memory_order_relaxed);
// If old_count was negative, there were waiters.
if (old_count < 0)
{
// Calculate how many actually need a signal.
// If we have 5 waiters (count == -5) and we post 10,
// we only signal 5.
int to_signal = std::min(-old_count, n);
m_semaphore.post_n(to_signal);
}
}
____________
Loopless, no CAS, just accounting.
--- PyGate Linux v1.5.13
* Origin: Dragon's Lair, PyGate NNTP<>Fido Gate (3:633/10)