Liste des Groupes | Revenir à cl c++ |
On 4/26/2025 12:25 AM, Bonita Montero wrote:
>
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 !
So, do that. It's your software. Do what you like. This is a very old debate. Take your contrived test and just, roll with it. Whatever.There's nothing to debate, I've measured it: If you awake a single
Les messages affichés proviennent d'usenet.