Deutsch English Français Italiano |
<vue65u$2aggi$2@dont-email.me> View for Bookmarking (what is this?) Look up another Usenet article |
Path: ...!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!eternal-september.org!.POSTED!not-for-mail From: "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> Newsgroups: comp.lang.c++ Subject: Re: signalling a condvar from inside vs. signalling a condvar von outside Date: Thu, 24 Apr 2025 13:15:57 -0700 Organization: A noiseless patient Spider Lines: 42 Message-ID: <vue65u$2aggi$2@dont-email.me> References: <vte0g6$pmgv$1@raubtier-asyl.eternal-september.org> <vtpcnt$384n4$1@dont-email.me> <vtpu86$3qnsh$1@raubtier-asyl.eternal-september.org> <vtq3dt$3vg77$1@dont-email.me> <vtqo57$hi7r$1@raubtier-asyl.eternal-september.org> <vtrf3u$15mgp$1@dont-email.me> <vtsph1$2d55o$1@raubtier-asyl.eternal-september.org> <vtu9un$3mhje$1@dont-email.me> <vtub8i$3o27s$1@raubtier-asyl.eternal-september.org> <nPOMP.335105$j2D.258162@fx09.iad> <vu0f8m$1nm7v$2@raubtier-asyl.eternal-september.org> <eVVMP.1467426$BrX.929148@fx12.iad> <vu3obr$kp0a$2@dont-email.me> <vu4j24$1fq9b$1@raubtier-asyl.eternal-september.org> <vu6nrs$3b29s$1@dont-email.me> <vu78mg$3t3v4$1@raubtier-asyl.eternal-september.org> <vu925c$1esv8$1@dont-email.me> <vu9uqk$2bldm$1@raubtier-asyl.eternal-september.org> <vue5hl$2aggi$1@dont-email.me> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit Injection-Date: Thu, 24 Apr 2025 22:15:59 +0200 (CEST) Injection-Info: dont-email.me; posting-host="9ab23ff6e21fe9bbc243a2a98cfc6588"; logging-data="2441746"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3eJnaVBKaE92+WcEMYgc/J7p9ELixemE=" User-Agent: Mozilla Thunderbird Cancel-Lock: sha1:RgRFXNBrgATy+Al8+FDWZB5eQ1E= In-Reply-To: <vue5hl$2aggi$1@dont-email.me> Content-Language: en-US Bytes: 3251 On 4/24/2025 1:05 PM, Chris M. Thomasson wrote: > On 4/22/2025 10:46 PM, Bonita Montero wrote: >> 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; } ); I must be missing something here. Where is your predicate for your cv.wait? >> --signalled; [...]