Sujet : Re: Solving thundering Herd with glibc...
De : Bonita.Montero (at) *nospam* gmail.com (Bonita Montero)
Groupes : comp.lang.c++Date : 26. Apr 2025, 08:25:22
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <vui1np$1tfb1$1@raubtier-asyl.eternal-september.org>
References : 1 2 3 4 5 6 7
User-Agent : Mozilla Thunderbird
Am 26.04.2025 um 08:26 schrieb Bonita Montero:
Am 25.04.2025 um 22:01 schrieb Chris M. Thomasson:
> If you say so... Too busy right now. Perhaps sometime later on tonight.
If there would be a thundering herd problem with glibc's condvar it
would happen very often with my code since I awake 31 threads at once
with my machine.
I just tried to awaken all 31 threads from outside holding the mutex,
but not from inside:
for( size_t r = N; r; --r )
{
unique_lock lock( mtx );
signalled = nClients;
ai.store( nClients, memory_order_relaxed );
lock.unlock();
if( argc < 2 )
cv.notify_all();
else
for( int c = nClients; c; cv.notify_one(), --c );
bs.acquire();
}
The result: 7.500 context switches per thread, not 3.000.
10000 rounds,
7498.06 context switches pe thread
So never signal a condvar to multiple threads from outside !