Sujet : Re: A simple futex'd benaphore
De : chris.m.thomasson.1 (at) *nospam* gmail.com (Chris M. Thomasson)
Groupes : comp.lang.c++Date : 06. Apr 2026, 23:39:54
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <10r1cnr$2eeev$2@dont-email.me>
References : 1 2
User-Agent : Mozilla Thunderbird
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.
Haut de la page
Les messages affichés proviennent d'usenet.
NewsPortal