Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

Nothing ever becomes real until it is experienced. -- John Keats


devel / comp.lang.c / Re: Book or tutorial on standard C threads

SubjectAuthor
* Book or tutorial on standard C threadsMehdi Amini
+* Re: Book or tutorial on standard C threadsBonita Montero
|`* Re: Book or tutorial on standard C threadsKenny McCormack
| `- Re: Book or tutorial on standard C threadsBonita Montero
+* Re: Book or tutorial on standard C threadsThiago Adams
|`* Re: Book or tutorial on standard C threadsBonita Montero
| `* Re: Book or tutorial on standard C threadsScott Lurndal
|  `* Re: Book or tutorial on standard C threadsBonita Montero
|   +* Re: Book or tutorial on standard C threadsGuillaume
|   |`- Re: Book or tutorial on standard C threadsBonita Montero
|   `* Re: Book or tutorial on standard C threadsMalcolm McLean
|    `* Re: Book or tutorial on standard C threadsBonita Montero
|     `* Re: Book or tutorial on standard C threadsBart
|      +- Re: Book or tutorial on standard C threadsBonita Montero
|      +* Re: Book or tutorial on standard C threadsScott Lurndal
|      |+- Re: Book or tutorial on standard C threadsBonita Montero
|      |`- Re: Book or tutorial on standard C threadsChris M. Thomasson
|      `* Re: Book or tutorial on standard C threadsBonita Montero
|       +* Re: Book or tutorial on standard C threadsBonita Montero
|       |`* Re: Book or tutorial on standard C threadsBart
|       | +* Re: Book or tutorial on standard C threadsBonita Montero
|       | |`* Re: Book or tutorial on standard C threadsBart
|       | | +- Re: Book or tutorial on standard C threadsBen Bacarisse
|       | | `* Re: Book or tutorial on standard C threadsBonita Montero
|       | |  `* Re: Book or tutorial on standard C threadsBart
|       | |   `- Re: Book or tutorial on standard C threadsBonita Montero
|       | `* Re: Book or tutorial on standard C threadsDavid Brown
|       |  +* Re: Book or tutorial on standard C threadsBart
|       |  |+- Re: Book or tutorial on standard C threadsBonita Montero
|       |  |+* Re: Book or tutorial on standard C threadsDavid Brown
|       |  ||+* Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |||+* Re: Book or tutorial on standard C threadsBonita Montero
|       |  ||||`- Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |||`- Re: Book or tutorial on standard C threadsDavid Brown
|       |  ||`* Re: Book or tutorial on standard C threadsBart
|       |  || `- Re: Book or tutorial on standard C threadsDavid Brown
|       |  |`* Re: Book or tutorial on standard C threadsBen Bacarisse
|       |  | `* Re: Book or tutorial on standard C threadsBart
|       |  |  `* Re: Book or tutorial on standard C threadsBonita Montero
|       |  |   `* Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |    +* Re: Book or tutorial on standard C threadsBonita Montero
|       |  |    |`* Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |    | `- Re: Book or tutorial on standard C threadsBonita Montero
|       |  |    `* Re: Book or tutorial on standard C threadsBen Bacarisse
|       |  |     `* Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |      `* Re: Book or tutorial on standard C threadsBart
|       |  |       +- Re: Book or tutorial on standard C threadsBonita Montero
|       |  |       `* Re: Book or tutorial on standard C threadsÖö Tiib
|       |  |        `* Re: Book or tutorial on standard C threadsMalcolm McLean
|       |  |         `- Re: Book or tutorial on standard C threadsÖö Tiib
|       |  `* Re: Book or tutorial on standard C threadsScott Lurndal
|       |   +- Re: Book or tutorial on standard C threadsDavid Brown
|       |   `- Re: Book or tutorial on standard C threadsBonita Montero
|       `* Re: Book or tutorial on standard C threadsBart
|        `* Re: Book or tutorial on standard C threadsBonita Montero
|         `* Re: Book or tutorial on standard C threadsScott Lurndal
|          `- Re: Book or tutorial on standard C threadsBonita Montero
+* Re: Book or tutorial on standard C threadsChris M. Thomasson
|`* Re: Book or tutorial on standard C threadsBen Bacarisse
| `* Re: Book or tutorial on standard C threadsChris M. Thomasson
|  `- Re: Book or tutorial on standard C threadsChris M. Thomasson
`* Re: Book or tutorial on standard C threadsChris M. Thomasson
 `- Re: Book or tutorial on standard C threadsBonita Montero

Pages:123
Re: Book or tutorial on standard C threads

<sDLuJ.126488$np6.2766@fx46.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19439&group=comp.lang.c#19439

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsfeed.xs4all.nl!newsfeed8.news.xs4all.nl!news-out.netnews.com!news.alt.net!fdc2.netnews.com!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx46.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Book or tutorial on standard C threads
Newsgroups: comp.lang.c
References: <sp1gtv$nht$1@dont-email.me> <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com> <spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad> <spal3l$hh8$1@dont-email.me> <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com> <spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me> <spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me> <spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
Lines: 27
Message-ID: <sDLuJ.126488$np6.2766@fx46.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Thu, 16 Dec 2021 18:32:56 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Thu, 16 Dec 2021 18:32:56 GMT
X-Received-Bytes: 1843
 by: Scott Lurndal - Thu, 16 Dec 2021 18:32 UTC

David Brown <david.brown@hesbynett.no> writes:

>But C++ /does/ have several alternatives to a long list of booleans like
>this. The simplest would be:
>
>enum class FlagA { True, False };
>enum class FlagB { True, False };
>
>void foo(FlagA a, FlagB b);
>
>void bar(void) {
> foo(FlagA::True, FlagB::False);
>}
>
>You can't get this wrong and call "foo(FlagB::True, FlagA::False)" - the
>compiler would spot the error. Strong types like this for parameters
>can help if you have a long parameter list.

Although 'true' and 'false' by themselves don't transmit anything useful
at the call site.

enum class DMAtype { Flat, ScatterGather, None };
enum class ERRmode { Recover, Abort, Ignore };

foo(DMAType::Flat, ERRmode::Recover);

Enhances readability and maintainability.

Re: Book or tutorial on standard C threads

<spg2nl$u2i$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19441&group=comp.lang.c#19441

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:06:28 +0100
Organization: A noiseless patient Spider
Lines: 6
Message-ID: <spg2nl$u2i$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 19:06:29 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e4386c8391e0a62735831cf701b50dd";
logging-data="30802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/Xk/dbJGx1o19XXLxlWqlUCcTR5CxLaB0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:+qfKLWUZHaTOw73daX23GAhVn+U=
In-Reply-To: <spfurq$3ll$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Dec 2021 19:06 UTC

Am 16.12.2021 um 19:00 schrieb Bart:

> To implement BM's example, 'update' and 'nTLBs' would need to be static,
> or copied to a static variable.

No, that would be an unclean solution.

Re: Book or tutorial on standard C threads

<spg2s4$u2i$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19442&group=comp.lang.c#19442

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:08:52 +0100
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <spg2s4$u2i$2@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfjmm$gun$1@dont-email.me>
<spfnln$e7j$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 19:08:52 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e4386c8391e0a62735831cf701b50dd";
logging-data="30802"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+D2TOklx5Ye/fjl+0BSzDv9MnaDbjbbyA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:3EkyeDWU0XO0mMDZWOIXAeeRNG4=
In-Reply-To: <spfnln$e7j$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Dec 2021 19:08 UTC

Am 16.12.2021 um 16:57 schrieb Bart:

> The docs for CPUID will be full of named bitfields; surely there is some
> way of naming those values instead of hard-coding meaningless numbers
> for shifts and masks.

Bitfields aren't absolutely compatible among x86-compilers.
So I extract them manuall.

> How many more lines would this example have been without lambdas?

Each push would have to be expanded and gatherTlbs would be twice.
That's an enormous amount of code.

Rest of your nonsense unread.

Re: Book or tutorial on standard C threads

<spg36r$2ok$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19443&group=comp.lang.c#19443

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:14:34 +0100
Organization: A noiseless patient Spider
Lines: 115
Message-ID: <spg36r$2ok$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 19:14:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c5380de63587e5edca61de9ce276e88";
logging-data="2836"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+juhY7hJ2IbvG8MU5Nvo9Hmq283erfFEE="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:i6Db+JEwk2t+vH5V+cg1W78YIxo=
In-Reply-To: <spfurq$3ll$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Thu, 16 Dec 2021 19:14 UTC

On 16/12/2021 19:00, Bart wrote:
> On 16/12/2021 16:24, David Brown wrote:
>> On 16/12/2021 15:16, Bart wrote:
>>> On 16/12/2021 06:54, Bonita Montero wrote:
>>>> Here's another good example of using long lambdas:
>>>>
>>>>           auto gatherTLBs = [&]( bool update ) -> size_t
>>>>           {
>>>>               size_t nTLBs = 0;
>>>>               auto push = [&]( bool l2, bool code, bool _4k, bool
>>>> _2M4M, bool _1G, unsigned n, unsigned ways, bool update )
>>>>               {
>>
>> <snip>
>>
>>>
>>> So, it looks like your emphasis is different aspects: those elusive
>>> lambdas (which doesn't help readability at all, unless it would be even
>>> worse without them), rather than doing something about basic
>>> readability.
>>
>> The lambdas here are nothing more nor less than function-local
>> functions.  Neither C nor C++ has support for local functions (unlike
>> Pascal, Ada, and many other languages - including gcc extended C).
>> Lambdas can certainly be convenient for that, and are safer, easier and
>> better scoped than using macros.
>
> So the lambda here is the local 'function' that includes that '[&]`
> (according to BB)?

The syntax for a lambda in C++ is basically a "[]" bit that can include
captures (by value or reference) that replaces the function name in a
normal function definition. And the return type is either deduced
automatically, or given with the newer "-> T" syntax rather than ahead
of the function name.

The simplest lambda is therefore: [](){}, and can be defined then
immediately called as [](){}(). C++ is a happy language with lots of
smilies!

>
> That's not what I'd think of as a 'lambda', which would be a function
> (parameter-spec and body) embedded in an expression - code to be
> evaluated later not as encountered.

Yes, that is also a way to use lambdas. They can do many things. They
are popular as callbacks, or for when a function requires a
function-like object as a parameter (such as a sorting function that
needs a comparison function), as you can define the function where you
need it rather than somewhere else in the code. They can also have
captures, which are useful at times. And a function can return a
lambda, meaning that you now have the possibility of a functional
programming style. (An example would be if you have "filter" functions
- you could have a "compose" function that takes two filter functions as
parameters and returns a lambda that combines them.)

But you can also use them as "normal" function definitions, except that
it is possible to use them in smaller scopes than file, namespace or as
class methods. So the following are approximately the same:

int foo(int x, int y) { return x + y; }
auto foo(int x, int y) { return x + y; }
auto foo(int x, int y) -> int { return x + y; }

auto foo = [](int x, int y) { return x + y; }
auto foo = [](int x, int y) -> int { return x + y; }

If you are familiar with lambdas in Python, they are quite similar in
C++ - except that Python uses the keyword "lambda" and the way captures
is done is different. If you are familiar with Lua, all function
definitions are actually done as lambdas, with "normal" function
definitions being syntactic sugar for assigning a lambda to a name.

>
> I'm surprised that even gnu C++ doesn't have local functions (or does it?).

<https://gcc.gnu.org/onlinedocs/gcc/Nested-Functions.html>

They are supported in C (I think the compiler support was made when gcc
support for Ada was introduced, and then adding them as a C extension
was easy). They are not supported in C++, which is fine - you don't
need them when you have lambdas as lambdas cover everything you can do
with local functions, plus much more.

>
> In that case a more suitable and more useful feature would have been
> local functions.
>

Eh, no. Lambdas are more general. (But in a more limited and simpler
language, nested function support might be enough, and it is almost
certainly easier to implement in the compiler.)

> (Which I used to implemented, but I kept them simple to avoid problems
> with accessing or capturing surrounding variables: accesses to
> stack-allocated variables of the enclosing function(s) were banned; but
> everything else was accessible.
>
> To implement BM's example, 'update' and 'nTLBs' would need to be static,
> or copied to a static variable.
>
> I no longer have them because they were never used, and they caused
> problems when an 'end' was left out, as that was only detected at the
> end of the file rather than at the start of the next function, which was
> interpreted as nested.)

I can't say I ever used nested functions more than once or twice when
using languages that have always supported them (such as Pascal). You
quickly end up with too much in the outer function, and too much
indentation. And if the language requires (or encourages) a style of
defining things at the start of the function definition, there is often
little to be gained compared to just making the nested function a
file-scope function. With C++ (or Python), it's easy and natural to
make the lambdas just where you need them, making them more useful (to
me, at least).

Re: Book or tutorial on standard C threads

<spg3ut$5n2$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19444&group=comp.lang.c#19444

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: david.br...@hesbynett.no (David Brown)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:27:25 +0100
Organization: A noiseless patient Spider
Lines: 35
Message-ID: <spg3ut$5n2$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<sDLuJ.126488$np6.2766@fx46.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 19:27:25 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c5380de63587e5edca61de9ce276e88";
logging-data="5858"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+3lE99RC4eayPBVvQzsk0dRhuMXuo7G58="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:fYSDegT6VuVJxTSnUuJiMRhK51o=
In-Reply-To: <sDLuJ.126488$np6.2766@fx46.iad>
Content-Language: en-GB
 by: David Brown - Thu, 16 Dec 2021 19:27 UTC

On 16/12/2021 19:32, Scott Lurndal wrote:
> David Brown <david.brown@hesbynett.no> writes:
>
>> But C++ /does/ have several alternatives to a long list of booleans like
>> this. The simplest would be:
>>
>> enum class FlagA { True, False };
>> enum class FlagB { True, False };
>>
>> void foo(FlagA a, FlagB b);
>>
>> void bar(void) {
>> foo(FlagA::True, FlagB::False);
>> }
>>
>> You can't get this wrong and call "foo(FlagB::True, FlagA::False)" - the
>> compiler would spot the error. Strong types like this for parameters
>> can help if you have a long parameter list.
>
> Although 'true' and 'false' by themselves don't transmit anything useful
> at the call site.
>
> enum class DMAtype { Flat, ScatterGather, None };
> enum class ERRmode { Recover, Abort, Ignore };
>
> foo(DMAType::Flat, ERRmode::Recover);
>
> Enhances readability and maintainability.
>

Of course. This was just an example of a relatively small improvement.
There are other ways to do better. (And "True" and "False" may be
entirely sufficient if the type name is good enough -
EnableAutoMode::True is hard to better.)

Re: Book or tutorial on standard C threads

<spg4a6$61h$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19446&group=comp.lang.c#19446

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:33:25 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <spg4a6$61h$3@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<sDLuJ.126488$np6.2766@fx46.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 19:33:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e4386c8391e0a62735831cf701b50dd";
logging-data="6193"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18dhEnImb5otQPAQ04qQDVD7HdzZ0gfOAA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:HA0OfT9kQUVPV3gOFKXI9vknd+M=
In-Reply-To: <sDLuJ.126488$np6.2766@fx46.iad>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Dec 2021 19:33 UTC

Am 16.12.2021 um 19:32 schrieb Scott Lurndal:
> David Brown <david.brown@hesbynett.no> writes:
>
>> But C++ /does/ have several alternatives to a long list of booleans like
>> this. The simplest would be:
>>
>> enum class FlagA { True, False };
>> enum class FlagB { True, False };
>>
>> void foo(FlagA a, FlagB b);
>>
>> void bar(void) {
>> foo(FlagA::True, FlagB::False);
>> }
>>
>> You can't get this wrong and call "foo(FlagB::True, FlagA::False)" - the
>> compiler would spot the error. Strong types like this for parameters
>> can help if you have a long parameter list.
>
> Although 'true' and 'false' by themselves don't transmit anything useful
> at the call site.
>
> enum class DMAtype { Flat, ScatterGather, None };
> enum class ERRmode { Recover, Abort, Ignore };
>
> foo(DMAType::Flat, ERRmode::Recover);
>
> Enhances readability and maintainability.

I mostly use enums in my own classes and there I don't use scoped
enums. It's just cumbersome to type ClassName::EnumName::EnumValue.
But I would also scope global enums.

Re: Book or tutorial on standard C threads

<spg8n1$9d8$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19451&group=comp.lang.c#19451

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 20:48:33 +0000
Organization: A noiseless patient Spider
Lines: 39
Message-ID: <spg8n1$9d8$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfjmm$gun$1@dont-email.me>
<spfnln$e7j$1@dont-email.me> <spg2s4$u2i$2@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 20:48:33 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3043536772e7831927a8259101779feb";
logging-data="9640"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19JIj8yj+9+EG+hzcxdwxXNsPwHmWUG4IE="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:/cewcqotQoSuzWiQXxUYFTxuL6w=
In-Reply-To: <spg2s4$u2i$2@dont-email.me>
 by: Bart - Thu, 16 Dec 2021 20:48 UTC

On 16/12/2021 19:08, Bonita Montero wrote:
> Am 16.12.2021 um 16:57 schrieb Bart:
>
>> The docs for CPUID will be full of named bitfields; surely there is
>> some way of naming those values instead of hard-coding meaningless
>> numbers for shifts and masks.
>
> Bitfields aren't absolutely compatible among x86-compilers.
> So I extract them manuall.
>
>> How many more lines would this example have been without lambdas?
>
> Each push would have to be expanded and gatherTlbs would be twice.
> That's an enormous amount of code.

It's already a considerable amount of code, for a seemingly simple task.
Maybe enough that you can't see the wood for the trees.

gatherTLBs() is already called twice; all those push() calls have to be
done once just to count how many TLBS, then again for real.

And all to reserve a size for tlbs which is pointless since the size is
so small; it will be 8 or 12. Either start from empty, or reserve 8 or
12 slots.

Each push() call also includes an 'update' parameter, not necessary
since it can see the update parameter of the enclosing gatherTLBs function.

gatherTLBs() seems to be yet another lambda, the purpose of which is
unclear from the supplied context.

It's not clear where tlbs comes from; a global visible to gatherTLBs?

What is clear that you are just using this stuff because you can. The
result is code more elaborate than necessary and using more advanced
features than necessary.

Given access to the cpuid() routine used here, a version in C could
easily be simpler.

Re: Book or tutorial on standard C threads

<87r1acusuf.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19456&group=comp.lang.c#19456

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 21:45:28 +0000
Organization: A noiseless patient Spider
Lines: 46
Message-ID: <87r1acusuf.fsf@bsb.me.uk>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=iso-8859-1
Content-Transfer-Encoding: 8bit
Injection-Info: reader02.eternal-september.org; posting-host="b9f7989dd930ff4732a641e9d197fd11";
logging-data="29240"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX19IXruL8HmO3pao8EgZCEu4mxiE60vy8Ek="
Cancel-Lock: sha1:5URo7WJcFh4qpfjiTTmkiv3SMyU=
sha1:GRCQpWGxpHz71+5BHPkh5kedDUM=
X-BSB-Auth: 1.3e3f107ec0ac81f7f8b7.20211216214528GMT.87r1acusuf.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 16 Dec 2021 21:45 UTC

Bart <bc@freeuk.com> writes:

> On 16/12/2021 16:24, David Brown wrote:
>> On 16/12/2021 15:16, Bart wrote:
>>> On 16/12/2021 06:54, Bonita Montero wrote:
>>>> Here's another good example of using long lambdas:
>>>>
>>>>          auto gatherTLBs = [&]( bool update ) -> size_t
>>>>          {
>>>>              size_t nTLBs = 0;
>>>>              auto push = [&]( bool l2, bool code, bool _4k, bool
>>>> _2M4M, bool _1G, unsigned n, unsigned ways, bool update )
>>>>              {
>> <snip>
>>
>>>
>>> So, it looks like your emphasis is different aspects: those elusive
>>> lambdas (which doesn't help readability at all, unless it would be even
>>> worse without them), rather than doing something about basic readability.
>>
>> The lambdas here are nothing more nor less than function-local
>> functions. Neither C nor C++ has support for local functions (unlike
>> Pascal, Ada, and many other languages - including gcc extended C).
>> Lambdas can certainly be convenient for that, and are safer, easier and
>> better scoped than using macros.
>
> So the lambda here is the local 'function' that includes that '[&]`
> (according to BB)?
>
> That's not what I'd think of as a 'lambda', which would be a function
> (parameter-spec and body) embedded in an expression - code to be
> evaluated later not as encountered.

The lambda posted /was/ embedded in an expression. Sure, it was the
entire expression used to initialise what will be, in effect, a name for
an anonymous, but if you don't have scoped function declarations, that's
the way to do it.

> I'm surprised that even gnu C++ doesn't have local functions (or does
> it?).

gnu C does, but not gnu C++. The C++ lambda solution is standard,
though.

--
Ben.

Re: Book or tutorial on standard C threads

<spggi3$k89$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19460&group=comp.lang.c#19460

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 23:02:28 +0000
Organization: A noiseless patient Spider
Lines: 51
Message-ID: <spggi3$k89$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <87r1acusuf.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 23:02:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4529ebeb088a50bedf53766b4b294c1f";
logging-data="20745"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+05bcDNoBKF+ON3AVR82qxehMaSPLDrZQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:bo/oSCBxvG2xEKEhV0bUezYg/r4=
In-Reply-To: <87r1acusuf.fsf@bsb.me.uk>
 by: Bart - Thu, 16 Dec 2021 23:02 UTC

On 16/12/2021 21:45, Ben Bacarisse wrote:
> Bart <bc@freeuk.com> writes:
>
>> On 16/12/2021 16:24, David Brown wrote:
>>> On 16/12/2021 15:16, Bart wrote:
>>>> On 16/12/2021 06:54, Bonita Montero wrote:
>>>>> Here's another good example of using long lambdas:
>>>>>
>>>>>          auto gatherTLBs = [&]( bool update ) -> size_t
>>>>>          {
>>>>>              size_t nTLBs = 0;
>>>>>              auto push = [&]( bool l2, bool code, bool _4k, bool
>>>>> _2M4M, bool _1G, unsigned n, unsigned ways, bool update )
>>>>>              {
>>> <snip>
>>>
>>>>
>>>> So, it looks like your emphasis is different aspects: those elusive
>>>> lambdas (which doesn't help readability at all, unless it would be even
>>>> worse without them), rather than doing something about basic readability.
>>>
>>> The lambdas here are nothing more nor less than function-local
>>> functions. Neither C nor C++ has support for local functions (unlike
>>> Pascal, Ada, and many other languages - including gcc extended C).
>>> Lambdas can certainly be convenient for that, and are safer, easier and
>>> better scoped than using macros.
>>
>> So the lambda here is the local 'function' that includes that '[&]`
>> (according to BB)?
>>
>> That's not what I'd think of as a 'lambda', which would be a function
>> (parameter-spec and body) embedded in an expression - code to be
>> evaluated later not as encountered.
>
> The lambda posted /was/ embedded in an expression. Sure, it was the
> entire expression used to initialise what will be, in effect, a name for
> an anonymous, but if you don't have scoped function declarations, that's
> the way to do it.
>
>> I'm surprised that even gnu C++ doesn't have local functions (or does
>> it?).
>
> gnu C does, but not gnu C++. The C++ lambda solution is standard,
> though.

I got the impression that BM is using lambdas because nested functions
don't exist. So it's not quite as surprising that they would use them
heavily.

Although I wouldn't bother even with nested functions for that example code.

Re: Book or tutorial on standard C threads

<spgk56$ovh$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19466&group=comp.lang.c#19466

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 16:03:47 -0800
Organization: A noiseless patient Spider
Lines: 63
Message-ID: <spgk56$ovh$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 00:03:50 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c8839452139dcaf4cfc3d8eff7656b44";
logging-data="25585"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/J8olCDQSVZDOYQuRrouz58+tdJHoIORA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:XTbTRrjlFr/NhCQG+ac+WVMoWRM=
In-Reply-To: <sp1gtv$nht$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 17 Dec 2021 00:03 UTC

On 12/10/2021 10:36 PM, Mehdi Amini wrote:
> Hi,
>
> Which book or tutorial would you recommend for standard C threads
> introduced in C11 ?

Call me old fashioned, but I still love this simple type of setup...
_____________________
#include <iostream>
#include <thread>
#include <atomic>
#include <algorithm>

struct ct_shared_state
{ std::atomic<int> m_foo;
};

void
ct_thread(ct_shared_state& shared)
{ shared.m_foo.fetch_add(1, std::memory_order_relaxed);
}

#define CT_THREADS 32

int main()
{ std::cout << "Hello World!\n\n";
std::cout.flush();

ct_shared_state shared_state = { { 1 } };

{
std::thread threads[CT_THREADS];

for (unsigned int i = 0; i < CT_THREADS; ++i)
{
threads[i] = std::thread(ct_thread, std::ref(shared_state));
}

for (unsigned int i = 0; i < CT_THREADS; ++i)
{
threads[i].join();
}
}

std::cout << shared_state.m_foo.load(std::memory_order_relaxed) *
11 + 303;

std::cout << "\n\nFin!\n\n";

return 0;
} _____________________

666

;^)

Old school. ;^)

Re: Book or tutorial on standard C threads

<878rwkt7g5.fsf@bsb.me.uk>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19469&group=comp.lang.c#19469

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: ben.use...@bsb.me.uk (Ben Bacarisse)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 00:12:58 +0000
Organization: A noiseless patient Spider
Lines: 15
Message-ID: <878rwkt7g5.fsf@bsb.me.uk>
References: <sp1gtv$nht$1@dont-email.me> <spgk56$ovh$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="28408566c190b4dbe1f1624967533111";
logging-data="21838"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX182t/2/AsNdp4H1QfG80Q9tsshY9GWIZGg="
Cancel-Lock: sha1:h9tXhkoPXCh5dYxBoiqbIL9HQ20=
sha1:vMLxs0u7kWIT0VEF5p/xrudcRiY=
X-BSB-Auth: 1.50a3c41313741db04dee.20211217001258GMT.878rwkt7g5.fsf@bsb.me.uk
 by: Ben Bacarisse - Fri, 17 Dec 2021 00:12 UTC

"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:

> On 12/10/2021 10:36 PM, Mehdi Amini wrote:
>> Hi,
>> Which book or tutorial would you recommend for standard C threads
>> introduced in C11 ?
>
> Call me old fashioned, but I still love this simple type of setup...
> _____________________
> #include <iostream>

The OP is asking about C.

--
Ben.

Re: Book or tutorial on standard C threads

<spgnpq$tg0$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19470&group=comp.lang.c#19470

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 17:05:59 -0800
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <spgnpq$tg0$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me> <spgk56$ovh$1@dont-email.me>
<878rwkt7g5.fsf@bsb.me.uk>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 01:06:02 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c8839452139dcaf4cfc3d8eff7656b44";
logging-data="30208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+Y6A3DIpKSA25kaSkrIWAnaP/DuqJJ+eA="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:Wt/SMY7O8oOqSKehSAYI2HIHUJY=
In-Reply-To: <878rwkt7g5.fsf@bsb.me.uk>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 17 Dec 2021 01:05 UTC

On 12/16/2021 4:12 PM, Ben Bacarisse wrote:
> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>
>> On 12/10/2021 10:36 PM, Mehdi Amini wrote:
>>> Hi,
>>> Which book or tutorial would you recommend for standard C threads
>>> introduced in C11 ?
>>
>> Call me old fashioned, but I still love this simple type of setup...
>> _____________________
>> #include <iostream>
>
> The OP is asking about C.
>

Indeed. Fwiw, the last time I tried to get a C11 compiler to work was in
Pelles C:

http://www.smorgasbordet.com/pellesc

Re: Book or tutorial on standard C threads

<spgnsb$tg0$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19471&group=comp.lang.c#19471

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: chris.m....@gmail.com (Chris M. Thomasson)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Thu, 16 Dec 2021 17:07:22 -0800
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <spgnsb$tg0$2@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me> <spgk56$ovh$1@dont-email.me>
<878rwkt7g5.fsf@bsb.me.uk> <spgnpq$tg0$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 01:07:23 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="c8839452139dcaf4cfc3d8eff7656b44";
logging-data="30208"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/yXhlUP15JQfH5SASbrpfdnrDRRIUZlsM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:nv8Ogg+pRYlHpsN2x/BpAlAobu4=
In-Reply-To: <spgnpq$tg0$1@dont-email.me>
Content-Language: en-US
 by: Chris M. Thomasson - Fri, 17 Dec 2021 01:07 UTC

On 12/16/2021 5:05 PM, Chris M. Thomasson wrote:
> On 12/16/2021 4:12 PM, Ben Bacarisse wrote:
>> "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> writes:
>>
>>> On 12/10/2021 10:36 PM, Mehdi Amini wrote:
>>>> Hi,
>>>> Which book or tutorial would you recommend for standard C threads
>>>> introduced in C11 ?
>>>
>>> Call me old fashioned, but I still love this simple type of setup...
>>> _____________________
>>> #include <iostream>
>>
>> The OP is asking about C.
>>
>
> Indeed. Fwiw, the last time I tried to get a C11 compiler to work was in
> Pelles C:
>
> http://www.smorgasbordet.com/pellesc
>

read all:

https://groups.google.com/g/comp.lang.c/c/gtD8weVPIjg

Re: Book or tutorial on standard C threads

<spha58$af7$2@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19473&group=comp.lang.c#19473

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 07:19:20 +0100
Organization: A noiseless patient Spider
Lines: 31
Message-ID: <spha58$af7$2@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfjmm$gun$1@dont-email.me>
<spfnln$e7j$1@dont-email.me> <spg2s4$u2i$2@dont-email.me>
<spg8n1$9d8$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 06:19:20 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a0167108212bfc0a20f4accb7116e27";
logging-data="10727"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18kdRbc7PsLyJAC/eD8H5uo6lnttgD+w0g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:ADfrybiRWqaDPpYxPdmdtITXBKA=
In-Reply-To: <spg8n1$9d8$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 17 Dec 2021 06:19 UTC

Am 16.12.2021 um 21:48 schrieb Bart:

> And all to reserve a size for tlbs which is pointless since the size is
> so small; it will be 8 or 12. Either start from empty, or reserve 8 or
> 12 slots.

Doesn't matter. It's just a little effort to have it called twice
and it saves some CPU-time for sure.

> Each push() call also includes an 'update' parameter, not necessary
> since it can see the update parameter of the enclosing gatherTLBs function.

That's a matter of taste.

> gatherTLBs() seems to be yet another lambda, the purpose of which is
> unclear from the supplied context.

It's called twice and therefore a lamda makes sense.

> It's not clear where tlbs comes from; a global visible to gatherTLBs?

You don't know the code where gatherTLBs is embedded in.

> What is clear that you are just using this stuff because you can.

No, because it safes a huge amount of code and its the fastest solution.

> Given access to the cpuid() routine used here, a version in C could
> easily be simpler.

No, for sure not.

Re: Book or tutorial on standard C threads

<sphqj1$e9d$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19481&group=comp.lang.c#19481

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 10:59:45 +0000
Organization: A noiseless patient Spider
Lines: 139
Message-ID: <sphqj1$e9d$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 17 Dec 2021 10:59:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4529ebeb088a50bedf53766b4b294c1f";
logging-data="14637"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/tM6f1GQ0Av0p5L+XI/ucK1wpPEHRatkc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:4YUZCpmZWd9SGt2vm3Ts3ZbMbSQ=
In-Reply-To: <spdfc4$1l6$1@dont-email.me>
 by: Bart - Fri, 17 Dec 2021 10:59 UTC

On 15/12/2021 19:23, Bonita Montero wrote:
> Am 15.12.2021 um 18:26 schrieb Bart:
>> On 15/12/2021 16:53, Bonita Montero wrote:
>>> Am 15.12.2021 um 13:02 schrieb Malcolm McLean:
>>>> On Tuesday, 14 December 2021 at 17:43:28 UTC, Bonita Montero wrote:
>>>>>> Simply? If your thread function is so simple that it makes
>>>>>> sense to write it as a lambda, you probably should not be
>>>>>> using threads.
>>>>> You're so silly to think lambdas are suitable only for simple things.
>>>>> I regulary use complex lambdas as jthread-"functions" which inherit
>>>>> the initiators context through [&].
>>>>>
>>>> I write mainly procedural C++. But it's easier to pass a trivial little
>>>> lambda to std::sort than to write a free-standing comparison function.
>>>> I rarely write code which accepts lambdas, just as I rarely write code
>>>> which declares templates, though I call such code quite frequently.
>>>
>>> I even use often templated lambdas.
>>
>> You would!
>>
>> You just /have/ to use the most elaborate toys at your disposal -
>> preferably as many at the same time as possible - and combine them in
>> ways that make people's heads spin.
>>
>> And yet you're always pushing the agenda that C++ somehow makes
>> everything a piece of cake!
>
>
> That's an example of my lambda-style:
>
>         auto buildChain = [&]<CmdLineParams::type_t Type>( bool
> smtThreaded, unsigned toThread )
>         {
>             auto updateStarts = [&]<typename MappingFn>( MappingFn
> mappingFn )
>                 requires requires( MappingFn mappingFn, size_t i )
>                 {
>                     { mappingFn( i ) } -> same_as<size_t>;
>                 }
>             {
>                 for( unsigned nThreads = 1; nThreads <= toThread;
> ++nThreads )
>                 {
>                     vector<link_t *> &starts = chainStarts[nThreads - 1];
>                     double gap = (double)(ptrdiff_t)n / (int)nThreads;
>                     for( unsigned t = 0; t != nThreads; ++t )
>                         starts[t] = &links[mappingFn(
> (ptrdiff_t)((int)t * gap) )];
>                 }
>             };
>             if constexpr( Type == CmdLineParams::LINEAR || Type ==
> CmdLineParams::XLINEAR )
>             {
>                 auto linearConcat = [&]<typename MappingFn>( MappingFn
> mappingFn )
>                     requires requires( MappingFn mappingFn, size_t i )
>                     {
>                         { mappingFn( i ) } -> same_as<size_t>;
>                     }
>                 {
>                     for( size_t i = 0; i != n; ++i )
>                         links[i].next = &links[mappingFn( mappingFn( i
> ) + 1 & idxMask)];
>                 };
>                 if constexpr( Type == CmdLineParams::LINEAR )
>                 {
>                     auto directMap = []( size_t i ) { return i; };
>                     linearConcat( directMap );
>                     updateStarts( directMap );
>                 }
>                 else
>                 {
>                     size_t inverter = (size_t)0x5555555555555555u &
> idxMask;
>                     auto invertedMap = [&]( size_t i ) { return i ^
> inverter; };
>                     linearConcat( invertedMap );
>                     updateStarts( invertedMap );
>                 }
>                 return;
>             }
>             unsigned l2ThrTlbBits = l2TlbBits - (unsigned)(smtThreaded
> && l2TlbBits),
>                      l1ThrTlbBits = l1TlbBits - (unsigned)(smtThreaded
> && l1TlbBits);
>             unsigned l1Bits, l2Bits, outerBits;
>             size_t l2Mask, outerMask;
>             auto maskFromBits = []( unsigned bits ) -> size_t { return
> ((size_t)1 << bits) - 1; };
>             if constexpr( Type == CmdLineParams::TLB_RANDOM )
>                 if( bits > l2ThrTlbBits + pageBits )
>                     outerBits = bits - (l2ThrTlbBits + pageBits),
>                     outerMask = maskFromBits( outerBits ),
>                     l2Bits = l2ThrTlbBits - l1ThrTlbBits,
>                     l2Mask = maskFromBits( l2Bits ),
>                     l1Bits = l1ThrTlbBits + pageBits - linkBits;
>                 else if( bits > l1ThrTlbBits + pageBits )
>                     outerBits = 0,
>                     outerMask = 0,
>                     l2Bits = bits - (l1ThrTlbBits + pageBits),
>                     l2Mask = maskFromBits( l2Bits ),
>                     l1Bits = l1ThrTlbBits + pageBits - linkBits;
>                 else
>                     outerBits = 0,
>                     outerMask = 0,
>                     l2Bits = 0,
>                     l2Mask = 0,
>                     l1Bits = bits - linkBits;
>             else
>                 l1Bits = bits - linkBits;
>             auto flipIndex = [&]( size_t i ) -> size_t
>             {
>                 static unsigned const SZT_BITS = sizeof(size_t) *
> CHAR_BIT;
>                 size_t rL1 = reverseBits( i ) >> SZT_BITS - l1Bits;
>                 if constexpr( Type != CmdLineParams::TLB_RANDOM )
>                     return rL1;
>                 size_t rL2 = reverseBits( i >> l1Bits ) >> SZT_BITS -
> l2Bits & l2Mask,
>                        rOuter = reverseBits( i >> l2Bits + l1Bits ) >>
> SZT_BITS - outerBits & outerMask;
>                 return rL1 + (rL2 << l1Bits) + (rOuter << l2Bits +
> l1Bits);
>             };
>             for( size_t rI = 0; rI != n; ++rI )
>                 links[rI].next = &links[flipIndex( flipIndex( rI ) + 1
> & idxMask )];
>             updateStarts( flipIndex );
>         };
>
> Without lambdas and even more templated lambdas the code
> would become very complicated.

Now that I know which bits are lambdas, and now that I know that you
mainly use lambdas to implement local functions, a missing C++ feature,
this code isn't really that remarkable.

It's just overly elaborate which is typical of your coding style.

Re: Book or tutorial on standard C threads

<sphujv$qm0$3@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19482&group=comp.lang.c#19482

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 13:08:30 +0100
Organization: A noiseless patient Spider
Lines: 114
Message-ID: <sphujv$qm0$3@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <sphqj1$e9d$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 17 Dec 2021 12:08:31 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a0167108212bfc0a20f4accb7116e27";
logging-data="27328"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18Si0dIl/lomhJ8vLwFYzsvXkmSSVbFIFQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:6vuth4FsCZFHkseopXo5QTkdy90=
In-Reply-To: <sphqj1$e9d$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Fri, 17 Dec 2021 12:08 UTC

Am 17.12.2021 um 11:59 schrieb Bart:

>> That's an example of my lambda-style:
>>
>>          auto buildChain = [&]<CmdLineParams::type_t Type>( bool
>> smtThreaded, unsigned toThread )
>>          {
>>              auto updateStarts = [&]<typename MappingFn>( MappingFn
>> mappingFn )
>>                  requires requires( MappingFn mappingFn, size_t i )
>>                  {
>>                      { mappingFn( i ) } -> same_as<size_t>;
>>                  }
>>              {
>>                  for( unsigned nThreads = 1; nThreads <= toThread;
>> ++nThreads )
>>                  {
>>                      vector<link_t *> &starts = chainStarts[nThreads -
>> 1];
>>                      double gap = (double)(ptrdiff_t)n / (int)nThreads;
>>                      for( unsigned t = 0; t != nThreads; ++t )
>>                          starts[t] = &links[mappingFn(
>> (ptrdiff_t)((int)t * gap) )];
>>                  }
>>              };
>>              if constexpr( Type == CmdLineParams::LINEAR || Type ==
>> CmdLineParams::XLINEAR )
>>              {
>>                  auto linearConcat = [&]<typename MappingFn>(
>> MappingFn mappingFn )
>>                      requires requires( MappingFn mappingFn, size_t i )
>>                      {
>>                          { mappingFn( i ) } -> same_as<size_t>;
>>                      }
>>                  {
>>                      for( size_t i = 0; i != n; ++i )
>>                          links[i].next = &links[mappingFn( mappingFn(
>> i ) + 1 & idxMask)];
>>                  };
>>                  if constexpr( Type == CmdLineParams::LINEAR )
>>                  {
>>                      auto directMap = []( size_t i ) { return i; };
>>                      linearConcat( directMap );
>>                      updateStarts( directMap );
>>                  }
>>                  else
>>                  {
>>                      size_t inverter = (size_t)0x5555555555555555u &
>> idxMask;
>>                      auto invertedMap = [&]( size_t i ) { return i ^
>> inverter; };
>>                      linearConcat( invertedMap );
>>                      updateStarts( invertedMap );
>>                  }
>>                  return;
>>              }
>>              unsigned l2ThrTlbBits = l2TlbBits -
>> (unsigned)(smtThreaded && l2TlbBits),
>>                       l1ThrTlbBits = l1TlbBits -
>> (unsigned)(smtThreaded && l1TlbBits);
>>              unsigned l1Bits, l2Bits, outerBits;
>>              size_t l2Mask, outerMask;
>>              auto maskFromBits = []( unsigned bits ) -> size_t {
>> return ((size_t)1 << bits) - 1; };
>>              if constexpr( Type == CmdLineParams::TLB_RANDOM )
>>                  if( bits > l2ThrTlbBits + pageBits )
>>                      outerBits = bits - (l2ThrTlbBits + pageBits),
>>                      outerMask = maskFromBits( outerBits ),
>>                      l2Bits = l2ThrTlbBits - l1ThrTlbBits,
>>                      l2Mask = maskFromBits( l2Bits ),
>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>                  else if( bits > l1ThrTlbBits + pageBits )
>>                      outerBits = 0,
>>                      outerMask = 0,
>>                      l2Bits = bits - (l1ThrTlbBits + pageBits),
>>                      l2Mask = maskFromBits( l2Bits ),
>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>                  else
>>                      outerBits = 0,
>>                      outerMask = 0,
>>                      l2Bits = 0,
>>                      l2Mask = 0,
>>                      l1Bits = bits - linkBits;
>>              else
>>                  l1Bits = bits - linkBits;
>>              auto flipIndex = [&]( size_t i ) -> size_t
>>              {
>>                  static unsigned const SZT_BITS = sizeof(size_t) *
>> CHAR_BIT;
>>                  size_t rL1 = reverseBits( i ) >> SZT_BITS - l1Bits;
>>                  if constexpr( Type != CmdLineParams::TLB_RANDOM )
>>                      return rL1;
>>                  size_t rL2 = reverseBits( i >> l1Bits ) >> SZT_BITS -
>> l2Bits & l2Mask,
>>                         rOuter = reverseBits( i >> l2Bits + l1Bits )
>> >> SZT_BITS - outerBits & outerMask;
>>                  return rL1 + (rL2 << l1Bits) + (rOuter << l2Bits +
>> l1Bits);
>>              };
>>              for( size_t rI = 0; rI != n; ++rI )
>>                  links[rI].next = &links[flipIndex( flipIndex( rI ) +
>> 1 & idxMask )];
>>              updateStarts( flipIndex );
>>          };
>>
>> Without lambdas and even more templated lambdas the code
>> would become very complicated.
>
> Now that I know which bits are lambdas, and now that I know that you
> mainly use lambdas to implement local functions, a missing C++ feature,
> this code isn't really that remarkable.

Lambdas are local functions and make the code _much_ more
readable if you use them properly - like in the above example.

Re: Book or tutorial on standard C threads

<GR2vJ.153777$qz4.91873@fx97.iad>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19485&group=comp.lang.c#19485

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx97.iad.POSTED!not-for-mail
X-newsreader: xrn 9.03-beta-14-64bit
Sender: scott@dragon.sl.home (Scott Lurndal)
From: sco...@slp53.sl.home (Scott Lurndal)
Reply-To: slp53@pacbell.net
Subject: Re: Book or tutorial on standard C threads
Newsgroups: comp.lang.c
References: <sp1gtv$nht$1@dont-email.me> <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com> <spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad> <spal3l$hh8$1@dont-email.me> <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com> <spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me> <spdfc4$1l6$1@dont-email.me> <sphqj1$e9d$1@dont-email.me> <sphujv$qm0$3@dont-email.me>
Lines: 118
Message-ID: <GR2vJ.153777$qz4.91873@fx97.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Fri, 17 Dec 2021 16:25:10 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Fri, 17 Dec 2021 16:25:10 GMT
X-Received-Bytes: 7648
X-Original-Bytes: 7597
 by: Scott Lurndal - Fri, 17 Dec 2021 16:25 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 17.12.2021 um 11:59 schrieb Bart:
>
>>> That's an example of my lambda-style:
>>>
>>>          auto buildChain = [&]<CmdLineParams::type_t Type>( bool
>>> smtThreaded, unsigned toThread )
>>>          {
>>>              auto updateStarts = [&]<typename MappingFn>( MappingFn
>>> mappingFn )
>>>                  requires requires( MappingFn mappingFn, size_t i )
>>>                  {
>>>                      { mappingFn( i ) } -> same_as<size_t>;
>>>                  }
>>>              {
>>>                  for( unsigned nThreads = 1; nThreads <= toThread;
>>> ++nThreads )
>>>                  {
>>>                      vector<link_t *> &starts = chainStarts[nThreads -
>>> 1];
>>>                      double gap = (double)(ptrdiff_t)n / (int)nThreads;
>>>                      for( unsigned t = 0; t != nThreads; ++t )
>>>                          starts[t] = &links[mappingFn(
>>> (ptrdiff_t)((int)t * gap) )];
>>>                  }
>>>              };
>>>              if constexpr( Type == CmdLineParams::LINEAR || Type ==
>>> CmdLineParams::XLINEAR )
>>>              {
>>>                  auto linearConcat = [&]<typename MappingFn>(
>>> MappingFn mappingFn )
>>>                      requires requires( MappingFn mappingFn, size_t i )
>>>                      {
>>>                          { mappingFn( i ) } -> same_as<size_t>;
>>>                      }
>>>                  {
>>>                      for( size_t i = 0; i != n; ++i )
>>>                          links[i].next = &links[mappingFn( mappingFn(
>>> i ) + 1 & idxMask)];
>>>                  };
>>>                  if constexpr( Type == CmdLineParams::LINEAR )
>>>                  {
>>>                      auto directMap = []( size_t i ) { return i; };
>>>                      linearConcat( directMap );
>>>                      updateStarts( directMap );
>>>                  }
>>>                  else
>>>                  {
>>>                      size_t inverter = (size_t)0x5555555555555555u &
>>> idxMask;
>>>                      auto invertedMap = [&]( size_t i ) { return i ^
>>> inverter; };
>>>                      linearConcat( invertedMap );
>>>                      updateStarts( invertedMap );
>>>                  }
>>>                  return;
>>>              }
>>>              unsigned l2ThrTlbBits = l2TlbBits -
>>> (unsigned)(smtThreaded && l2TlbBits),
>>>                       l1ThrTlbBits = l1TlbBits -
>>> (unsigned)(smtThreaded && l1TlbBits);
>>>              unsigned l1Bits, l2Bits, outerBits;
>>>              size_t l2Mask, outerMask;
>>>              auto maskFromBits = []( unsigned bits ) -> size_t {
>>> return ((size_t)1 << bits) - 1; };
>>>              if constexpr( Type == CmdLineParams::TLB_RANDOM )
>>>                  if( bits > l2ThrTlbBits + pageBits )
>>>                      outerBits = bits - (l2ThrTlbBits + pageBits),
>>>                      outerMask = maskFromBits( outerBits ),
>>>                      l2Bits = l2ThrTlbBits - l1ThrTlbBits,
>>>                      l2Mask = maskFromBits( l2Bits ),
>>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>>                  else if( bits > l1ThrTlbBits + pageBits )
>>>                      outerBits = 0,
>>>                      outerMask = 0,
>>>                      l2Bits = bits - (l1ThrTlbBits + pageBits),
>>>                      l2Mask = maskFromBits( l2Bits ),
>>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>>                  else
>>>                      outerBits = 0,
>>>                      outerMask = 0,
>>>                      l2Bits = 0,
>>>                      l2Mask = 0,
>>>                      l1Bits = bits - linkBits;
>>>              else
>>>                  l1Bits = bits - linkBits;
>>>              auto flipIndex = [&]( size_t i ) -> size_t
>>>              {
>>>                  static unsigned const SZT_BITS = sizeof(size_t) *
>>> CHAR_BIT;
>>>                  size_t rL1 = reverseBits( i ) >> SZT_BITS - l1Bits;
>>>                  if constexpr( Type != CmdLineParams::TLB_RANDOM )
>>>                      return rL1;
>>>                  size_t rL2 = reverseBits( i >> l1Bits ) >> SZT_BITS -
>>> l2Bits & l2Mask,
>>>                         rOuter = reverseBits( i >> l2Bits + l1Bits )
>>> >> SZT_BITS - outerBits & outerMask;
>>>                  return rL1 + (rL2 << l1Bits) + (rOuter << l2Bits +
>>> l1Bits);
>>>              };
>>>              for( size_t rI = 0; rI != n; ++rI )
>>>                  links[rI].next = &links[flipIndex( flipIndex( rI ) +
>>> 1 & idxMask )];
>>>              updateStarts( flipIndex );
>>>          };
>>>
>>> Without lambdas and even more templated lambdas the code
>>> would become very complicated.
>>
>> Now that I know which bits are lambdas, and now that I know that you
>> mainly use lambdas to implement local functions, a missing C++ feature,
>> this code isn't really that remarkable.
>
>Lambdas are local functions and make the code _much_ more
>readable if you use them properly - like in the above example.

The above code is completely unreadable. And it was unreadable
even before being mangled by various NNTP clients.

Re: Book or tutorial on standard C threads

<spieea$18s$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19486&group=comp.lang.c#19486

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 17:38:32 +0100
Organization: A noiseless patient Spider
Lines: 121
Message-ID: <spieea$18s$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <sphqj1$e9d$1@dont-email.me>
<sphujv$qm0$3@dont-email.me> <GR2vJ.153777$qz4.91873@fx97.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 17 Dec 2021 16:38:34 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a0167108212bfc0a20f4accb7116e27";
logging-data="1308"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX195oIKotBA1fhyFIWBUq40BVMzH7E+7Gls="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:YtXVx+WYzaDHtCKcLHwi+k8tt+s=
In-Reply-To: <GR2vJ.153777$qz4.91873@fx97.iad>
Content-Language: de-DE
 by: Bonita Montero - Fri, 17 Dec 2021 16:38 UTC

Am 17.12.2021 um 17:25 schrieb Scott Lurndal:
> Bonita Montero <Bonita.Montero@gmail.com> writes:
>> Am 17.12.2021 um 11:59 schrieb Bart:
>>
>>>> That's an example of my lambda-style:
>>>>
>>>>          auto buildChain = [&]<CmdLineParams::type_t Type>( bool
>>>> smtThreaded, unsigned toThread )
>>>>          {
>>>>              auto updateStarts = [&]<typename MappingFn>( MappingFn
>>>> mappingFn )
>>>>                  requires requires( MappingFn mappingFn, size_t i )
>>>>                  {
>>>>                      { mappingFn( i ) } -> same_as<size_t>;
>>>>                  }
>>>>              {
>>>>                  for( unsigned nThreads = 1; nThreads <= toThread;
>>>> ++nThreads )
>>>>                  {
>>>>                      vector<link_t *> &starts = chainStarts[nThreads -
>>>> 1];
>>>>                      double gap = (double)(ptrdiff_t)n / (int)nThreads;
>>>>                      for( unsigned t = 0; t != nThreads; ++t )
>>>>                          starts[t] = &links[mappingFn(
>>>> (ptrdiff_t)((int)t * gap) )];
>>>>                  }
>>>>              };
>>>>              if constexpr( Type == CmdLineParams::LINEAR || Type ==
>>>> CmdLineParams::XLINEAR )
>>>>              {
>>>>                  auto linearConcat = [&]<typename MappingFn>(
>>>> MappingFn mappingFn )
>>>>                      requires requires( MappingFn mappingFn, size_t i )
>>>>                      {
>>>>                          { mappingFn( i ) } -> same_as<size_t>;
>>>>                      }
>>>>                  {
>>>>                      for( size_t i = 0; i != n; ++i )
>>>>                          links[i].next = &links[mappingFn( mappingFn(
>>>> i ) + 1 & idxMask)];
>>>>                  };
>>>>                  if constexpr( Type == CmdLineParams::LINEAR )
>>>>                  {
>>>>                      auto directMap = []( size_t i ) { return i; };
>>>>                      linearConcat( directMap );
>>>>                      updateStarts( directMap );
>>>>                  }
>>>>                  else
>>>>                  {
>>>>                      size_t inverter = (size_t)0x5555555555555555u &
>>>> idxMask;
>>>>                      auto invertedMap = [&]( size_t i ) { return i ^
>>>> inverter; };
>>>>                      linearConcat( invertedMap );
>>>>                      updateStarts( invertedMap );
>>>>                  }
>>>>                  return;
>>>>              }
>>>>              unsigned l2ThrTlbBits = l2TlbBits -
>>>> (unsigned)(smtThreaded && l2TlbBits),
>>>>                       l1ThrTlbBits = l1TlbBits -
>>>> (unsigned)(smtThreaded && l1TlbBits);
>>>>              unsigned l1Bits, l2Bits, outerBits;
>>>>              size_t l2Mask, outerMask;
>>>>              auto maskFromBits = []( unsigned bits ) -> size_t {
>>>> return ((size_t)1 << bits) - 1; };
>>>>              if constexpr( Type == CmdLineParams::TLB_RANDOM )
>>>>                  if( bits > l2ThrTlbBits + pageBits )
>>>>                      outerBits = bits - (l2ThrTlbBits + pageBits),
>>>>                      outerMask = maskFromBits( outerBits ),
>>>>                      l2Bits = l2ThrTlbBits - l1ThrTlbBits,
>>>>                      l2Mask = maskFromBits( l2Bits ),
>>>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>>>                  else if( bits > l1ThrTlbBits + pageBits )
>>>>                      outerBits = 0,
>>>>                      outerMask = 0,
>>>>                      l2Bits = bits - (l1ThrTlbBits + pageBits),
>>>>                      l2Mask = maskFromBits( l2Bits ),
>>>>                      l1Bits = l1ThrTlbBits + pageBits - linkBits;
>>>>                  else
>>>>                      outerBits = 0,
>>>>                      outerMask = 0,
>>>>                      l2Bits = 0,
>>>>                      l2Mask = 0,
>>>>                      l1Bits = bits - linkBits;
>>>>              else
>>>>                  l1Bits = bits - linkBits;
>>>>              auto flipIndex = [&]( size_t i ) -> size_t
>>>>              {
>>>>                  static unsigned const SZT_BITS = sizeof(size_t) *
>>>> CHAR_BIT;
>>>>                  size_t rL1 = reverseBits( i ) >> SZT_BITS - l1Bits;
>>>>                  if constexpr( Type != CmdLineParams::TLB_RANDOM )
>>>>                      return rL1;
>>>>                  size_t rL2 = reverseBits( i >> l1Bits ) >> SZT_BITS -
>>>> l2Bits & l2Mask,
>>>>                         rOuter = reverseBits( i >> l2Bits + l1Bits )
>>>>>> SZT_BITS - outerBits & outerMask;
>>>>                  return rL1 + (rL2 << l1Bits) + (rOuter << l2Bits +
>>>> l1Bits);
>>>>              };
>>>>              for( size_t rI = 0; rI != n; ++rI )
>>>>                  links[rI].next = &links[flipIndex( flipIndex( rI ) +
>>>> 1 & idxMask )];
>>>>              updateStarts( flipIndex );
>>>>          };
>>>>
>>>> Without lambdas and even more templated lambdas the code
>>>> would become very complicated.
>>>
>>> Now that I know which bits are lambdas, and now that I know that you
>>> mainly use lambdas to implement local functions, a missing C++ feature,
>>> this code isn't really that remarkable.
>>
>> Lambdas are local functions and make the code _much_ more
>> readable if you use them properly - like in the above example.
>
> The above code is completely unreadable. And it was unreadable
> even before being mangled by various NNTP clients.

The code is unreadable because you don't know what it's good for.

Re: Book or tutorial on standard C threads

<8daae9e6-5806-4798-98f9-dcdcf4815766n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19488&group=comp.lang.c#19488

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:5e47:: with SMTP id i7mr3354515qtx.600.1639762203936;
Fri, 17 Dec 2021 09:30:03 -0800 (PST)
X-Received: by 2002:ac8:5c03:: with SMTP id i3mr3506919qti.107.1639762203759;
Fri, 17 Dec 2021 09:30:03 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Fri, 17 Dec 2021 09:30:03 -0800 (PST)
In-Reply-To: <spg36r$2ok$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sp1gtv$nht$1@dont-email.me> <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me> <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me> <spdfc4$1l6$1@dont-email.me>
<spenqd$t0c$1@dont-email.me> <spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <spg36r$2ok$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <8daae9e6-5806-4798-98f9-dcdcf4815766n@googlegroups.com>
Subject: Re: Book or tutorial on standard C threads
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Fri, 17 Dec 2021 17:30:03 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 8
 by: Öö Tiib - Fri, 17 Dec 2021 17:30 UTC

On Thursday, 16 December 2021 at 21:14:46 UTC+2, David Brown wrote:
>
> The simplest lambda is therefore: [](){}, and can be defined then
> immediately called as [](){}(). C++ is a happy language with lots of
> smilies!

Yes. I've been surprised when some people say that it is oh so
readable.
Handy? Very. Happy? Perhaps. Readable? Hmm.

Re: Book or tutorial on standard C threads

<spijk0$7r9$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19490&group=comp.lang.c#19490

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 19:06:54 +0100
Organization: A noiseless patient Spider
Lines: 13
Message-ID: <spijk0$7r9$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <spg36r$2ok$1@dont-email.me>
<8daae9e6-5806-4798-98f9-dcdcf4815766n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Fri, 17 Dec 2021 18:06:56 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4a0167108212bfc0a20f4accb7116e27";
logging-data="8041"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/z14k5H+uBdeI8HJLjpUMqANuY/qAdqoQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:e7FE/xN9zpof/lx1BjtG/+U0xu8=
In-Reply-To: <8daae9e6-5806-4798-98f9-dcdcf4815766n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Fri, 17 Dec 2021 18:06 UTC

Am 17.12.2021 um 18:30 schrieb Öö Tiib:
> On Thursday, 16 December 2021 at 21:14:46 UTC+2, David Brown wrote:
>>
>> The simplest lambda is therefore: [](){}, and can be defined then
>> immediately called as [](){}(). C++ is a happy language with lots of
>> smilies!
>
> Yes. I've been surprised when some people say that it is oh so
> readable.
> Handy? Very. Happy? Perhaps. Readable? Hmm.

Yes, more readable because lambdas could save a lot of redundant code.

Re: Book or tutorial on standard C threads

<spikbg$djf$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19491&group=comp.lang.c#19491

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: bc...@freeuk.com (Bart)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Fri, 17 Dec 2021 18:19:29 +0000
Organization: A noiseless patient Spider
Lines: 50
Message-ID: <spikbg$djf$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <spg36r$2ok$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 17 Dec 2021 18:19:28 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="4529ebeb088a50bedf53766b4b294c1f";
logging-data="13935"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/GM+ZUF4St12hy/g4Ft2jEok2zKA8z7NM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:+n55VdvtBv+Wxxk/DLqyG0hNPEo=
In-Reply-To: <spg36r$2ok$1@dont-email.me>
 by: Bart - Fri, 17 Dec 2021 18:19 UTC

On 16/12/2021 19:14, David Brown wrote:
> On 16/12/2021 19:00, Bart wrote:

>> So the lambda here is the local 'function' that includes that '[&]`
>> (according to BB)?
>
> The syntax for a lambda in C++ is basically a "[]" bit that can include
> captures (by value or reference) that replaces the function name in a
> normal function definition. And the return type is either deduced
> automatically, or given with the newer "-> T" syntax rather than ahead
> of the function name.
>
> The simplest lambda is therefore: [](){}, and can be defined then
> immediately called as [](){}(). C++ is a happy language with lots of
> smilies!

I tried to add <> in there but it didn't work.

>> I no longer have them because they were never used, and they caused
>> problems when an 'end' was left out, as that was only detected at the
>> end of the file rather than at the start of the next function, which was
>> interpreted as nested.)
>
> I can't say I ever used nested functions more than once or twice when
> using languages that have always supported them (such as Pascal). You
> quickly end up with too much in the outer function, and too much
> indentation. And if the language requires (or encourages) a style of
> defining things at the start of the function definition, there is often
> little to be gained compared to just making the nested function a
> file-scope function. With C++ (or Python), it's easy and natural to
> make the lambdas just where you need them, making them more useful (to
> me, at least).

While I no longer support normal nested functions, I still allow
function definitions inside records (ie. structs in C, or classes in
C++, where they might be called methods).

Those can also be nested (although name resolution across more than one
level needs attention).

That serves to encapsulate a bunch of related functions, isolated from
the rest of the file, and can be used with no need to create an instance
of the record or call them as methods.

I tried to do the same with C++ classes, but I don't know the language
and got tied up in knots trying to make it work.

I wanted to show another approach to using nested functions and lambdas.
If C++ can't in fact do what I wanted, then it /could/ have done.

Re: Book or tutorial on standard C threads

<a2427c49-3f61-4e3e-8624-2da05bb9f9f5n@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19499&group=comp.lang.c#19499

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:6214:2423:: with SMTP id gy3mr1412826qvb.44.1639825665875;
Sat, 18 Dec 2021 03:07:45 -0800 (PST)
X-Received: by 2002:a05:620a:d93:: with SMTP id q19mr4390956qkl.9.1639825665738;
Sat, 18 Dec 2021 03:07:45 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 18 Dec 2021 03:07:45 -0800 (PST)
In-Reply-To: <spijk0$7r9$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sp1gtv$nht$1@dont-email.me> <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me> <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me> <spdfc4$1l6$1@dont-email.me>
<spenqd$t0c$1@dont-email.me> <spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <spg36r$2ok$1@dont-email.me> <8daae9e6-5806-4798-98f9-dcdcf4815766n@googlegroups.com>
<spijk0$7r9$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <a2427c49-3f61-4e3e-8624-2da05bb9f9f5n@googlegroups.com>
Subject: Re: Book or tutorial on standard C threads
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sat, 18 Dec 2021 11:07:45 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 17
 by: Öö Tiib - Sat, 18 Dec 2021 11:07 UTC

On Friday, 17 December 2021 at 20:07:08 UTC+2, Bonita Montero wrote:
> Am 17.12.2021 um 18:30 schrieb Öö Tiib:
> > On Thursday, 16 December 2021 at 21:14:46 UTC+2, David Brown wrote:
> >>
> >> The simplest lambda is therefore: [](){}, and can be defined then
> >> immediately called as [](){}(). C++ is a happy language with lots of
> >> smilies!
> >
> > Yes. I've been surprised when some people say that it is oh so
> > readable.
> > Handy? Very. Happy? Perhaps. Readable? Hmm.
> Yes, more readable because lambdas could save a lot of redundant code.

These were designed for that purpose. But my bots running over actual
code bases report that lambdas in actual reality are most frequent new
containers of copy-pasta.

Re: Book or tutorial on standard C threads

<spkl4g$9kd$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19505&group=comp.lang.c#19505

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Sat, 18 Dec 2021 13:45:04 +0100
Organization: A noiseless patient Spider
Lines: 58
Message-ID: <spkl4g$9kd$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <87r1acusuf.fsf@bsb.me.uk>
<spggi3$k89$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Sat, 18 Dec 2021 12:45:04 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="39aec95fcf390d4e22123bfed9ade6cb";
logging-data="9869"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+MTzfU31tnyZRWlrjYI04cUd1maBc9wT8="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:qYMTxLVEtT4VtcE95lQ7rVTIfX8=
In-Reply-To: <spggi3$k89$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 18 Dec 2021 12:45 UTC

Am 17.12.2021 um 00:02 schrieb Bart:
> On 16/12/2021 21:45, Ben Bacarisse wrote:
>> Bart <bc@freeuk.com> writes:
>>
>>> On 16/12/2021 16:24, David Brown wrote:
>>>> On 16/12/2021 15:16, Bart wrote:
>>>>> On 16/12/2021 06:54, Bonita Montero wrote:
>>>>>> Here's another good example of using long lambdas:
>>>>>>
>>>>>>            auto gatherTLBs = [&]( bool update ) -> size_t
>>>>>>            {
>>>>>>                size_t nTLBs = 0;
>>>>>>                auto push = [&]( bool l2, bool code, bool _4k, bool
>>>>>> _2M4M, bool _1G, unsigned n, unsigned ways, bool update )
>>>>>>                {
>>>> <snip>
>>>>
>>>>>
>>>>> So, it looks like your emphasis is different aspects: those elusive
>>>>> lambdas (which doesn't help readability at all, unless it would be
>>>>> even
>>>>> worse without them), rather than doing something about basic
>>>>> readability.
>>>>
>>>> The lambdas here are nothing more nor less than function-local
>>>> functions.  Neither C nor C++ has support for local functions (unlike
>>>> Pascal, Ada, and many other languages - including gcc extended C).
>>>> Lambdas can certainly be convenient for that, and are safer, easier and
>>>> better scoped than using macros.
>>>
>>> So the lambda here is the local 'function' that includes that '[&]`
>>> (according to BB)?
>>>
>>> That's not what I'd think of as a 'lambda', which would be a function
>>> (parameter-spec and body) embedded in an expression - code to be
>>> evaluated later not as encountered.
>>
>> The lambda posted /was/ embedded in an expression.  Sure, it was the
>> entire expression used to initialise what will be, in effect, a name for
>> an anonymous, but if you don't have scoped function declarations, that's
>> the way to do it.
>>
>>> I'm surprised that even gnu C++ doesn't have local functions (or does
>>> it?).
>>
>> gnu C does, but not gnu C++.  The C++ lambda solution is standard,
>> though.
>
>
> I got the impression that BM is using lambdas because nested functions
> don't exist. So it's not quite as surprising that they would use them
> heavily.
>
> Although I wouldn't bother even with nested functions for that example
> code.

Lambdas are a great relief and I think they're the most importand part
of C++11.

Re: Book or tutorial on standard C threads

<66650d26-8a35-432e-a065-d93ee7eac69an@googlegroups.com>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19509&group=comp.lang.c#19509

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ac8:4e96:: with SMTP id 22mr6347772qtp.76.1639836125466;
Sat, 18 Dec 2021 06:02:05 -0800 (PST)
X-Received: by 2002:a05:620a:a16:: with SMTP id i22mr4672228qka.362.1639836125174;
Sat, 18 Dec 2021 06:02:05 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border2.nntp.dca1.giganews.com!border1.nntp.dca1.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.c
Date: Sat, 18 Dec 2021 06:02:04 -0800 (PST)
In-Reply-To: <spkl4g$9kd$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=94.246.251.164; posting-account=pysjKgkAAACLegAdYDFznkqjgx_7vlUK
NNTP-Posting-Host: 94.246.251.164
References: <sp1gtv$nht$1@dont-email.me> <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me> <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me> <spdfc4$1l6$1@dont-email.me>
<spenqd$t0c$1@dont-email.me> <spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <87r1acusuf.fsf@bsb.me.uk> <spggi3$k89$1@dont-email.me>
<spkl4g$9kd$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <66650d26-8a35-432e-a065-d93ee7eac69an@googlegroups.com>
Subject: Re: Book or tutorial on standard C threads
From: oot...@hot.ee (Öö Tiib)
Injection-Date: Sat, 18 Dec 2021 14:02:05 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 75
 by: Öö Tiib - Sat, 18 Dec 2021 14:02 UTC

On Saturday, 18 December 2021 at 14:45:15 UTC+2, Bonita Montero wrote:
> Am 17.12.2021 um 00:02 schrieb Bart:
> > On 16/12/2021 21:45, Ben Bacarisse wrote:
> >> Bart <b...@freeuk.com> writes:
> >>
> >>> On 16/12/2021 16:24, David Brown wrote:
> >>>> On 16/12/2021 15:16, Bart wrote:
> >>>>> On 16/12/2021 06:54, Bonita Montero wrote:
> >>>>>> Here's another good example of using long lambdas:
> >>>>>>
> >>>>>> auto gatherTLBs = [&]( bool update ) -> size_t
> >>>>>> {
> >>>>>> size_t nTLBs = 0;
> >>>>>> auto push = [&]( bool l2, bool code, bool _4k, bool
> >>>>>> _2M4M, bool _1G, unsigned n, unsigned ways, bool update )
> >>>>>> {
> >>>> <snip>
> >>>>
> >>>>>
> >>>>> So, it looks like your emphasis is different aspects: those elusive
> >>>>> lambdas (which doesn't help readability at all, unless it would be
> >>>>> even
> >>>>> worse without them), rather than doing something about basic
> >>>>> readability.
> >>>>
> >>>> The lambdas here are nothing more nor less than function-local
> >>>> functions. Neither C nor C++ has support for local functions (unlike
> >>>> Pascal, Ada, and many other languages - including gcc extended C).
> >>>> Lambdas can certainly be convenient for that, and are safer, easier and
> >>>> better scoped than using macros.
> >>>
> >>> So the lambda here is the local 'function' that includes that '[&]`
> >>> (according to BB)?
> >>>
> >>> That's not what I'd think of as a 'lambda', which would be a function
> >>> (parameter-spec and body) embedded in an expression - code to be
> >>> evaluated later not as encountered.
> >>
> >> The lambda posted /was/ embedded in an expression. Sure, it was the
> >> entire expression used to initialise what will be, in effect, a name for
> >> an anonymous, but if you don't have scoped function declarations, that's
> >> the way to do it.
> >>
> >>> I'm surprised that even gnu C++ doesn't have local functions (or does
> >>> it?).
> >>
> >> gnu C does, but not gnu C++. The C++ lambda solution is standard,
> >> though.
> >
> >
> > I got the impression that BM is using lambdas because nested functions
> > don't exist. So it's not quite as surprising that they would use them
> > heavily.
> >
> > Although I wouldn't bother even with nested functions for that example
> > code.
> Lambdas are a great relief and I think they're the most importand part
> of C++11.

Lambdas are just syntax simplification of few things
and syntax improvements are not comparable with major performance
improvements that C++11 added. The amount of code saved and confusion
added is comparable with effect of auto.

From syntax sugar improvements the range-based-for and variadic
templates are also far better than lambdas because these make code
more elegant without adding any weird garbage or confusion.

C++11 added several performance improvements like move semantics,
constexpr, noexcept, split concepts of trivial classes and standard layout
classes, even underlying type of enum. These are all better than syntax
sugar because these help to have more efficient product.

Therefore only the optional cosmetic things like nullptr, final, override,
enum class, explicit, etc. are less important than lambdas.

Re: Book or tutorial on standard C threads

<spkrbh$i1h$1@dont-email.me>

  copy mid

https://www.novabbs.com/devel/article-flat.php?id=19511&group=comp.lang.c#19511

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: Bonita.M...@gmail.com (Bonita Montero)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Sat, 18 Dec 2021 15:31:13 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <spkrbh$i1h$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
<spahrt$o2h$1@dont-email.me> <Kg4uJ.77766$IB7.11471@fx02.iad>
<spal3l$hh8$1@dont-email.me>
<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
<spd6hp$t5b$1@dont-email.me> <spd8gl$dq4$1@dont-email.me>
<spdfc4$1l6$1@dont-email.me> <spenqd$t0c$1@dont-email.me>
<spfhn3$370$1@dont-email.me> <spfp7o$pv7$1@dont-email.me>
<spfurq$3ll$1@dont-email.me> <87r1acusuf.fsf@bsb.me.uk>
<spggi3$k89$1@dont-email.me> <spkl4g$9kd$1@dont-email.me>
<66650d26-8a35-432e-a065-d93ee7eac69an@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Sat, 18 Dec 2021 14:31:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="39aec95fcf390d4e22123bfed9ade6cb";
logging-data="18481"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/3BxCM9ugTxZxtdLddcSp1Umwy+fVjsAw="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:SU0q2S7vSSjAiCN0ZXZM+oxxoGI=
In-Reply-To: <66650d26-8a35-432e-a065-d93ee7eac69an@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Sat, 18 Dec 2021 14:31 UTC

> Lambdas are just syntax simplification of few things ...

No, it's not "just" syntax-simplification, it's the ease of use
to prevent a lot of redundant code and to write objects with only
a calling operator in one line.

> From syntax sugar improvements the range-based-for and variadic
> templates are also far better than lambdas ...

They're not comparable since they solve completely different
purposes.

> because these make code more elegant without adding any weird
> garbage or confusion.

Lambdas are not confusing. But variadic templates can be very confusing.

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor