Liste des Groupes | Revenir à cl c++ |
On 4/22/2025 10:46 PM, Bonita Montero wrote:I must be missing something here. Where is your predicate for your cv.wait?Now I wrote a little program to test if there's thundering herd problem
with glibc's mutex / condvar. This it is:
>
#include <iostream>
#include <thread>
#include <mutex>
#include <condition_variable>
#include <atomic>
#include <semaphore>
#include <vector>
#include <sys/resource.h>
>
using namespace std;
>
int main()
{
constexpr size_t N = 10'000;
int nClients = thread::hardware_concurrency() - 1;
mutex mtx;
int signalled = 0;
condition_variable cv;
atomic_int ai( 0 );
binary_semaphore bs( false );
vector<jthread> clients;
atomic_int64_t nVoluntary( 0 );
for( int c = nClients; c; --c )
clients.emplace_back( [&]
{
for( size_t r = N; r; --r )
{
unique_lock lock( mtx );
cv.wait( lock, [&] { return (bool)signalled; } );
[...]--signalled;
Les messages affichés proviennent d'usenet.