Warning: mysqli::__construct(): (HY000/1203): User howardkn already has more than 'max_user_connections' active connections in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\includes\artfuncs.php on line 21
Failed to connect to MySQL: (1203) User howardkn already has more than 'max_user_connections' active connections
Warning: mysqli::query(): Couldn't fetch mysqli in D:\Inetpub\vhosts\howardknight.net\al.howardknight.net\index.php on line 66
Article <vbs01c$3j5mc$1@raubtier-asyl.eternal-september.org>
Deutsch   English   Français   Italiano  
<vbs01c$3j5mc$1@raubtier-asyl.eternal-september.org>

View for Bookmarking (what is this?)
Look up another Usenet article

Path: ...!news.mixmin.net!eternal-september.org!feeder3.eternal-september.org!news.eternal-september.org!raubtier-asyl.eternal-september.org!.POSTED!not-for-mail
From: Bonita Montero <Bonita.Montero@gmail.com>
Newsgroups: comp.lang.c++
Subject: Re: counting_semaphore question
Date: Wed, 11 Sep 2024 13:48:04 +0200
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <vbs01c$3j5mc$1@raubtier-asyl.eternal-september.org>
References: <vbrqjj$3hvsd$1@dont-email.me>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 11 Sep 2024 13:47:57 +0200 (CEST)
Injection-Info: raubtier-asyl.eternal-september.org; posting-host="a58a4b43cc3412e7e6d63eb94bcf30e2";
	logging-data="3774156"; mail-complaints-to="abuse@eternal-september.org";	posting-account="U2FsdGVkX1+BjxLhNUUXJ4xmVupceaS5hXUpsdbJwWE="
User-Agent: Mozilla Thunderbird
Cancel-Lock: sha1:s/G9r+hvnSDUCECXYDzB27PFZKU=
In-Reply-To: <vbrqjj$3hvsd$1@dont-email.me>
Content-Language: de-DE
Bytes: 2269

Am 11.09.2024 um 12:15 schrieb Muttley@dastardlyhq.com:
> I've been looking at counting_semaphore and it looks useful but something
> that doesn't seem to be properly explained anywhere is the template
> parameter value. eg you can do:
> 
> std::counting_semaphore sem(2)
> 
> which will let a max of 2 threads into the protected block at a time or:
> 
> std::counting_semaphore<some number> sem(2)
> 
> such as
> 
> std::counting_semaphore<10> sem(2)
> 
> I don't understand what the '10' will do. ..

The ten gives an upper limit beyond the semaphore wont't increment.

Usually you won't need a C++20 semaphore yourself. For most purpose
the mutex and the condition_variable is sufficient.
But if you will build your own synchronization-primitives you inter-
nally would also need a semaphore. The semaphore class itself is
usually built on top of the system-provided futex. I implemented
a reader's writer lock with configurable priority for either rea-
ders or writers (std::shared_mutex only supports reader-priority)
and therefore I needed C++20's counting_semaphore and binary_sema-
phore (which is an template-alias for counting_senaphore<1>).