Rocksolid Light

Welcome to novaBBS (click a section below)

mail  files  register  newsreader  groups  login

Message-ID:  

There's got to be more to life than compile-and-go.


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
Book or tutorial on standard C threads

<sp1gtv$nht$1@dont-email.me>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!eternal-september.org!reader02.eternal-september.org!.POSTED!not-for-mail
From: atorr...@gmail.com (Mehdi Amini)
Newsgroups: comp.lang.c
Subject: Book or tutorial on standard C threads
Date: Sat, 11 Dec 2021 10:06:46 +0330
Organization: A noiseless patient Spider
Lines: 4
Message-ID: <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: Sat, 11 Dec 2021 06:36:47 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5abd655a18d38872ae23b3ba880fceed";
logging-data="24125"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/dAO6LfdtzdDNtCqyglYxt3EV6pDdS0Z0="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.14.0
Cancel-Lock: sha1:HaA3/FdqBfkOP4HY84eNaG7K8+k=
Content-Language: en-US
X-Mozilla-News-Host: snews://news.eternal-september.org:563
 by: Mehdi Amini - Sat, 11 Dec 2021 06:36 UTC

Hi,

Which book or tutorial would you recommend for standard C threads
introduced in C11 ?

Re: Book or tutorial on standard C threads

<sp1k0a$b9b$1@dont-email.me>

  copy mid

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

  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, 11 Dec 2021 08:29:14 +0100
Organization: A noiseless patient Spider
Lines: 8
Message-ID: <sp1k0a$b9b$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: Sat, 11 Dec 2021 07:29:14 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="fdc13100cba695686b5d78b30c4a1b7f";
logging-data="11563"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+7ig+T+AEMYa7UoJHbZFXBzhpSojmH74k="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:sdPwhzxlzldzOLjEqbirkFvRks8=
In-Reply-To: <sp1gtv$nht$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Sat, 11 Dec 2021 07:29 UTC

Am 11.12.2021 um 07:36 schrieb Mehdi Amini:
> Hi,
>
> Which book or tutorial would you recommend for standard C threads
> introduced in C11 ?

Better learn C++; C++11 threads are magnitudes more convenient.

Re: Book or tutorial on standard C threads

<sp6v9j$1q2vn$2@news.xmission.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!xmission!nnrp.xmission!.POSTED.shell.xmission.com!not-for-mail
From: gaze...@shell.xmission.com (Kenny McCormack)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Mon, 13 Dec 2021 08:12:35 -0000 (UTC)
Organization: The official candy of the new Millennium
Message-ID: <sp6v9j$1q2vn$2@news.xmission.com>
References: <sp1gtv$nht$1@dont-email.me> <sp1k0a$b9b$1@dont-email.me>
Injection-Date: Mon, 13 Dec 2021 08:12:35 -0000 (UTC)
Injection-Info: news.xmission.com; posting-host="shell.xmission.com:166.70.8.4";
logging-data="1903607"; mail-complaints-to="abuse@xmission.com"
X-Newsreader: trn 4.0-test77 (Sep 1, 2010)
Originator: gazelle@shell.xmission.com (Kenny McCormack)
 by: Kenny McCormack - Mon, 13 Dec 2021 08:12 UTC

In article <sp1k0a$b9b$1@dont-email.me>,
Bonita Montero <Bonita.Montero@gmail.com> wrote:
>Am 11.12.2021 um 07:36 schrieb Mehdi Amini:
>> Hi,
>>
>> Which book or tutorial would you recommend for standard C threads
>> introduced in C11 ?
>
>Better learn C++; C++11 threads are magnitudes more convenient.
>

Better still: Hire someone else to write your programs for you.

Then you don't have to learn anything.

Much, much more convenient.

--
The randomly chosen signature file that would have appeared here is more than 4
lines long. As such, it violates one or more Usenet RFCs. In order to remain
in compliance with said RFCs, the actual sig can be found at the following URL:
http://user.xmission.com/~gazelle/Sigs/DanQuayle

Re: Book or tutorial on standard C threads

<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:a05:620a:1a0b:: with SMTP id bk11mr32945848qkb.513.1639415788979;
Mon, 13 Dec 2021 09:16:28 -0800 (PST)
X-Received: by 2002:a05:620a:702:: with SMTP id 2mr24615617qkc.333.1639415788729;
Mon, 13 Dec 2021 09:16:28 -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: Mon, 13 Dec 2021 09:16:28 -0800 (PST)
In-Reply-To: <sp1gtv$nht$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=189.6.248.114; posting-account=xFcAQAoAAAAoWlfpQ6Hz2n-MU9fthxbY
NNTP-Posting-Host: 189.6.248.114
References: <sp1gtv$nht$1@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
Subject: Re: Book or tutorial on standard C threads
From: thiago.a...@gmail.com (Thiago Adams)
Injection-Date: Mon, 13 Dec 2021 17:16:28 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 21
 by: Thiago Adams - Mon, 13 Dec 2021 17:16 UTC

On Saturday, December 11, 2021 at 3:37:00 AM UTC-3, Mehdi Amini Valashani son of Bahram wrote:
> Hi,
>
> Which book or tutorial would you recommend for standard C threads
> introduced in C11 ?

Some sources:

- https://en.cppreference.com/w/c/thread

- the C standard

- Threads in C are based on the C++ version.
You if you learn the C++ version then C is similar in concepts. (not in code)
https://www.cplusplusconcurrencyinaction.com/

C threads are not implemented in many compilers. I use this library:
https://tinycthread.github.io/

Re: Book or tutorial on standard C threads

<spahf2$itf$2@dont-email.me>

  copy mid

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

  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: Tue, 14 Dec 2021 17:41:05 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <spahf2$itf$2@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me> <sp1k0a$b9b$1@dont-email.me>
<sp6v9j$1q2vn$2@news.xmission.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Dec 2021 16:41:06 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a2688fdba3476119951430ed70382d91";
logging-data="19375"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8IDAmd0Ejil3nr1kR/aYK5hQLJyOONlI="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:Nn2mAhR27oNxJdwccYxGVkusJpM=
In-Reply-To: <sp6v9j$1q2vn$2@news.xmission.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 14 Dec 2021 16:41 UTC

Am 13.12.2021 um 09:12 schrieb Kenny McCormack:
> In article <sp1k0a$b9b$1@dont-email.me>,
> Bonita Montero <Bonita.Montero@gmail.com> wrote:
>> Am 11.12.2021 um 07:36 schrieb Mehdi Amini:
>>> Hi,
>>>
>>> Which book or tutorial would you recommend for standard C threads
>>> introduced in C11 ?
>>
>> Better learn C++; C++11 threads are magnitudes more convenient.
>>
>
> Better still: Hire someone else to write your programs for you.

With C++ you've to learn a magnitude more than for C.
But you have much less code and the code is more
maintainable if you use the language properly.

Re: Book or tutorial on standard C threads

<spahrt$o2h$1@dont-email.me>

  copy mid

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

  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: Tue, 14 Dec 2021 17:47:56 +0100
Organization: A noiseless patient Spider
Lines: 10
Message-ID: <spahrt$o2h$1@dont-email.me>
References: <sp1gtv$nht$1@dont-email.me>
<c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Dec 2021 16:47:57 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a2688fdba3476119951430ed70382d91";
logging-data="24657"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8Qw1zZN6yUJ1OLvQB/YOezS0luCEqpNQ="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:JsF5pV0eaZe7LUsuhPWXH0uKKtw=
In-Reply-To: <c35539a6-316d-47b6-8c14-6a5a1070c6c5n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Tue, 14 Dec 2021 16:47 UTC

Am 13.12.2021 um 18:16 schrieb Thiago Adams:

> - Threads in C are based on the C++ version.
No, both ways are based on the facilites the operating systems
supply to you, but C++ has a higher abstraction-level here.
But in C++ they're much more convenient to use. F.e. you can
simply have a lambda with captures a a thread-function. Or
supply a number of arguments directly to a thread function
through the constructor of std::thread / std::jthread. Or
you have full RAII-ness for locking.

Re: Book or tutorial on standard C threads

<Kg4uJ.77766$IB7.11471@fx02.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!weretis.net!feeder8.news.weretis.net!newsreader4.netcologne.de!news.netcologne.de!peer02.ams1!peer.ams1.xlned.com!news.xlned.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx02.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>
Lines: 20
Message-ID: <Kg4uJ.77766$IB7.11471@fx02.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Tue, 14 Dec 2021 17:13:14 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Tue, 14 Dec 2021 17:13:14 GMT
X-Received-Bytes: 1385
 by: Scott Lurndal - Tue, 14 Dec 2021 17:13 UTC

Bonita Montero <Bonita.Montero@gmail.com> writes:
>Am 13.12.2021 um 18:16 schrieb Thiago Adams:
>
>> - Threads in C are based on the C++ version.
>No, both ways are based on the facilites the operating systems
>supply to you, but C++ has a higher abstraction-level here.
>But in C++ they're much more convenient to use.

Definitely arguable.

>F.e.

You should write z.b. or e.g. 'f.e.' is not a standard
abbreviation.

>you can simply have a lambda with captures a a thread-function.

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.

Re: Book or tutorial on standard C threads

<spal3l$hh8$1@dont-email.me>

  copy mid

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

  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: Tue, 14 Dec 2021 18:43:15 +0100
Organization: A noiseless patient Spider
Lines: 7
Message-ID: <spal3l$hh8$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Tue, 14 Dec 2021 17:43:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a2688fdba3476119951430ed70382d91";
logging-data="17960"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/NWOMR5SVlcOc4GQWsQBi6Ieod6n9LShM="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:+j5irlKZ8jPr4hdDiyvEwsnOeOM=
In-Reply-To: <Kg4uJ.77766$IB7.11471@fx02.iad>
Content-Language: de-DE
 by: Bonita Montero - Tue, 14 Dec 2021 17:43 UTC

> 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 [&].

Re: Book or tutorial on standard C threads

<spanfn$15i1$1@gioia.aioe.org>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!aioe.org!UgLt14+w9tVHe1BtIa3HDQ.user.46.165.242.75.POSTED!not-for-mail
From: mess...@bottle.org (Guillaume)
Newsgroups: comp.lang.c
Subject: Re: Book or tutorial on standard C threads
Date: Tue, 14 Dec 2021 19:23:38 +0100
Organization: Aioe.org NNTP Server
Message-ID: <spanfn$15i1$1@gioia.aioe.org>
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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Info: gioia.aioe.org; logging-data="38465"; posting-host="UgLt14+w9tVHe1BtIa3HDQ.user.gioia.aioe.org"; mail-complaints-to="abuse@aioe.org";
User-Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Content-Language: fr
X-Notice: Filtered by postfilter v. 0.9.2
 by: Guillaume - Tue, 14 Dec 2021 18:23 UTC

Le 14/12/2021 à 18:43, Bonita Montero a écrit :
>> 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 [&].

We'd sure be curious to have a look at this. :D

Re: Book or tutorial on standard C threads

<spaqj0$o5t$1@dont-email.me>

  copy mid

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

  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: Tue, 14 Dec 2021 20:16:47 +0100
Organization: A noiseless patient Spider
Lines: 14
Message-ID: <spaqj0$o5t$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> <spanfn$15i1$1@gioia.aioe.org>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Tue, 14 Dec 2021 19:16:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="a2688fdba3476119951430ed70382d91";
logging-data="24765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/8vr/pYyI94kdmwey6fGbYyPtKkDePXoc="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.3.2
Cancel-Lock: sha1:RQA9LETtvq0z9gLYzYmds+lHVFQ=
In-Reply-To: <spanfn$15i1$1@gioia.aioe.org>
Content-Language: de-DE
 by: Bonita Montero - Tue, 14 Dec 2021 19:16 UTC

Am 14.12.2021 um 19:23 schrieb Guillaume:
> Le 14/12/2021 à 18:43, Bonita Montero a écrit :
>>> 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 [&].
>
> We'd sure be curious to have a look at this. :D

Just long lambdas which use a lot of the inherited stackframe.

Re: Book or tutorial on standard C threads

<dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
X-Received: by 2002:ae9:e403:: with SMTP id q3mr8275741qkc.53.1639569758875;
Wed, 15 Dec 2021 04:02:38 -0800 (PST)
X-Received: by 2002:a05:6214:20ad:: with SMTP id 13mr2494158qvd.4.1639569758676;
Wed, 15 Dec 2021 04:02:38 -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: Wed, 15 Dec 2021 04:02:38 -0800 (PST)
In-Reply-To: <spal3l$hh8$1@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=2a00:23a8:400a:5601:f5d0:650f:e40c:485b;
posting-account=Dz2zqgkAAADlK5MFu78bw3ab-BRFV4Qn
NNTP-Posting-Host: 2a00:23a8:400a:5601:f5d0:650f:e40c:485b
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>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
Subject: Re: Book or tutorial on standard C threads
From: malcolm....@gmail.com (Malcolm McLean)
Injection-Date: Wed, 15 Dec 2021 12:02:38 +0000
Content-Type: text/plain; charset="UTF-8"
Lines: 13
 by: Malcolm McLean - Wed, 15 Dec 2021 12:02 UTC

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.

Re: Book or tutorial on standard C threads

<spd6hp$t5b$1@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 17:53:13 +0100
Organization: A noiseless patient Spider
Lines: 16
Message-ID: <spd6hp$t5b$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Dec 2021 16:53:13 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7d272f2309a1a02e9e02d59e54ae4a8c";
logging-data="29867"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18hfhJVJKfKU4uApHeKwB3Bl/YxF1yGvm0="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:xXIGpBl8U/UvVjr9wDY6p2DnmFw=
In-Reply-To: <dd0c4355-bae4-42d1-a1cf-5898cb7c7b50n@googlegroups.com>
Content-Language: de-DE
 by: Bonita Montero - Wed, 15 Dec 2021 16:53 UTC

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.

Re: Book or tutorial on standard C threads

<spd8gl$dq4$1@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 17:26:44 +0000
Organization: A noiseless patient Spider
Lines: 25
Message-ID: <spd8gl$dq4$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Dec 2021 17:26:45 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="19cd73d9872de243701536ff60a9ac5a";
logging-data="14148"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/RcyMvC1ckxWcLoQq77irS1ghXuOM4iJo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:aFv3OnF+xeP9dieibro9zmeTslU=
In-Reply-To: <spd6hp$t5b$1@dont-email.me>
 by: Bart - Wed, 15 Dec 2021 17:26 UTC

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!

Re: Book or tutorial on standard C threads

<spd8n9$cjs$2@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 18:30:17 +0100
Organization: A noiseless patient Spider
Lines: 28
Message-ID: <spd8n9$cjs$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Dec 2021 17:30:17 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7d272f2309a1a02e9e02d59e54ae4a8c";
logging-data="12924"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/BYUwkW3b43z6XqK6KEOvf7/OdjYQwq7U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:JxwhzaS9T0r2y0ur6FUEUwjuvOA=
In-Reply-To: <spd8gl$dq4$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 15 Dec 2021 17:30 UTC

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.

I use lambdas mostly to prevent redundant code in functions. And
I use templated lambdas for the same purpose but in addition when
the lambda is performance-critical. The resulting code is still
more readable than having multiply specialized code in the function.

Re: Book or tutorial on standard C threads

<hUpuJ.64138$zF3.21782@fx03.iad>

  copy mid

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

  copy link   Newsgroups: comp.lang.c
Path: i2pn2.org!i2pn.org!paganini.bofh.team!news.dns-netz.com!news.freedyn.net!newsreader4.netcologne.de!news.netcologne.de!peer03.ams1!peer.ams1.xlned.com!news.xlned.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!fx03.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>
Lines: 27
Message-ID: <hUpuJ.64138$zF3.21782@fx03.iad>
X-Complaints-To: abuse@usenetserver.com
NNTP-Posting-Date: Wed, 15 Dec 2021 17:49:01 UTC
Organization: UsenetServer - www.usenetserver.com
Date: Wed, 15 Dec 2021 17:49:01 GMT
X-Received-Bytes: 2153
 by: Scott Lurndal - Wed, 15 Dec 2021 17:49 UTC

Bart <bc@freeuk.com> writes:
>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 given the amount of time Bonita spends posting, I would
guess that most of the code written is for personal use, not
professional.

Re: Book or tutorial on standard C threads

<spdbjn$56e$2@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 19:19:36 +0100
Organization: A noiseless patient Spider
Lines: 32
Message-ID: <spdbjn$56e$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>
<hUpuJ.64138$zF3.21782@fx03.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Dec 2021 18:19:35 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7d272f2309a1a02e9e02d59e54ae4a8c";
logging-data="5326"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+pjqoHo4TyYfkNDLNVVX+UrvXVDVj265I="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:WYR6jaUTnARm72fdwpEsu29gMkQ=
In-Reply-To: <hUpuJ.64138$zF3.21782@fx03.iad>
Content-Language: de-DE
 by: Bonita Montero - Wed, 15 Dec 2021 18:19 UTC

Am 15.12.2021 um 18:49 schrieb Scott Lurndal:
> Bart <bc@freeuk.com> writes:
>> 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 given the amount of time Bonita spends posting, I would
> guess that most of the code written is for personal use, not
> professional.

My code isn't less readable because I use C++ partitially
in an unusual way. If everyone had this style in mind no
one would complain about that.

Re: Book or tutorial on standard C threads

<spdfc4$1l6$1@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 20:23:48 +0100
Organization: A noiseless patient Spider
Lines: 119
Message-ID: <spdfc4$1l6$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Wed, 15 Dec 2021 19:23:48 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="7d272f2309a1a02e9e02d59e54ae4a8c";
logging-data="1702"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18p5X62DsupXuhOdFb159I6I/IX8Mig3bo="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:3pkW8qm10QVBgW/NCJWM4Sy+sGc=
In-Reply-To: <spd8gl$dq4$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Wed, 15 Dec 2021 19:23 UTC

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.

Re: Book or tutorial on standard C threads

<spe5ln$9gs$2@dont-email.me>

  copy mid

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

  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: Wed, 15 Dec 2021 17:44:23 -0800
Organization: A noiseless patient Spider
Lines: 30
Message-ID: <spe5ln$9gs$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>
<hUpuJ.64138$zF3.21782@fx03.iad>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 01:44:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="68ebb6fb92c15ebce93e929f9c53f042";
logging-data="9756"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+K9yq03ApVVBvfZ+YGX4PuxZoRnTZj+ls="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:CUxa0IdaK0p1J1Dh2AUOJW6TYoI=
In-Reply-To: <hUpuJ.64138$zF3.21782@fx03.iad>
Content-Language: en-US
 by: Chris M. Thomasson - Thu, 16 Dec 2021 01:44 UTC

On 12/15/2021 9:49 AM, Scott Lurndal wrote:
> Bart <bc@freeuk.com> writes:
>> 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 given the amount of time Bonita spends posting, I would
> guess that most of the code written is for personal use, not
> professional.

Especially with some of the errors in the posted code...

Re: Book or tutorial on standard C threads

<spenqd$t0c$1@dont-email.me>

  copy mid

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

  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 07:54:06 +0100
Organization: A noiseless patient Spider
Lines: 56
Message-ID: <spenqd$t0c$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: 7bit
Injection-Date: Thu, 16 Dec 2021 06:54:05 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e4386c8391e0a62735831cf701b50dd";
logging-data="29708"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18BMj+UNocYGJULQ0Mepq7rbDWuxPH6UfU="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:gk3lLbmCY9EycxV9n5HKUnG/1vs=
In-Reply-To: <spdfc4$1l6$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Dec 2021 06:54 UTC

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 )
{
if( !n || !ways )
return;
++nTLBs;
if( update )
tlbs.emplace_back( (uint8_t)l2 + 1, !code ? tlb_descr::type_t::DATA
: tlb_descr::type_t::CODE, _4k, _2M4M, _2M4M, _1G, n, ways );
};
static auto longWays = []( uint8_t ways ) -> unsigned { return ways
!= 0xFF ? ways : -1; };
static unsigned const shortWays[0x10] = { 0, 1, 2, 0, 4, 0, 8, 0, 16,
0, 32, 48, 64, 96, 128, (unsigned)-1 };
cpuid( regs, 0x80000005u, 0 );
push( false, false, true, false, false, regs[1] >> 16 & 0x0FF,
longWays( regs[1] >> 24 ), update );
push( false, false, false, true, false, regs[0] >> 16 & 0x0FF,
longWays( regs[0] >> 24 ), update );
push( false, true, true, false, false, regs[1] & 0xFF, longWays(
regs[1] >> 8 & 0xFF ), update );
push( false, true, false, true, false, regs[0] & 0xFF, longWays(
regs[0] >> 8 & 0xFF ), update );
cpuid( regs, 0x80000006u, 0 );
push( true, false, true, false, false, regs[1] >> 16 & 0x0FFF,
shortWays[regs[1] >> 28], update );
push( true, false, false, true, false, regs[0] >> 16 & 0x0FFF,
shortWays[regs[0] >> 28], update );
push( true, true, true, false, false, regs[1] & 0xFFF,
shortWays[regs[1] >> 12 & 0xF], update );
push( true, true, false, true, false, regs[0] & 0xFFF,
shortWays[regs[0] >> 12 & 0xF], update );
if( has1GPages() && maxExtCpuid >= 0x80000019u )
cpuid( regs, 0x80000019u, 0 ),
push( false, false, false, false, true, regs[0] >> 16 & 0xFFF,
shortWays[regs[0] >> 28], update ),
push( false, true, false, false, true, regs[0] & 0xFFF,
shortWays[regs[1] >> 12 & 0xF], update ),
push( true, false, false, false, true, regs[1] >> 16 & 0xFFF,
shortWays[regs[0] >> 28], update ),
push( true, true, false, false, true, regs[1] & 0xFFF,
shortWays[regs[1] >> 12 & 0xF], update );
return nTLBs;
};
tlbs.reserve( gatherTLBs( false ) );
gatherTLBs( true );

This function collects the TLB-sizes for AMD-CPUs. In one mode it just
counts the number of entries (update = false), in th other it fills the
vector tlbs. That prevents any reallocation of tlbs.
And the push lambda prevents a huge amount of redundant code.

Re: Book or tutorial on standard C threads

<spfhn3$370$1@dont-email.me>

  copy mid

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

  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 14:16:04 +0000
Organization: A noiseless patient Spider
Lines: 164
Message-ID: <spfhn3$370$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 14:16:03 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3043536772e7831927a8259101779feb";
logging-data="3296"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+e9GbU4dLMN3ZvQonn/L2OXt5ZjYhwwHY="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:Sbf40Ic0pmihUn+GXPwPoZzTlys=
In-Reply-To: <spenqd$t0c$1@dont-email.me>
 by: Bart - Thu, 16 Dec 2021 14:16 UTC

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 )
>             {
>                 if( !n || !ways )
>                     return;
>                 ++nTLBs;
>                 if( update )
>                     tlbs.emplace_back( (uint8_t)l2 + 1, !code ?
> tlb_descr::type_t::DATA : tlb_descr::type_t::CODE, _4k, _2M4M, _2M4M,
> _1G, n, ways );
>             };
>             static auto longWays = []( uint8_t ways ) -> unsigned {
> return ways != 0xFF ? ways : -1; };
>             static unsigned const shortWays[0x10] = { 0, 1, 2, 0, 4, 0,
> 8, 0, 16, 0, 32, 48, 64, 96, 128, (unsigned)-1 };
>             cpuid( regs, 0x80000005u, 0 );
>             push( false, false, true, false, false, regs[1] >> 16 &
> 0x0FF, longWays( regs[1] >> 24 ), update );
>             push( false, false, false, true, false, regs[0] >> 16 &
> 0x0FF, longWays( regs[0] >> 24 ), update );
>             push( false, true, true, false, false, regs[1] & 0xFF,
> longWays( regs[1] >> 8 & 0xFF ), update );
>             push( false, true, false, true, false, regs[0] & 0xFF,
> longWays( regs[0] >> 8 & 0xFF ), update );
>             cpuid( regs, 0x80000006u, 0 );
>             push( true, false, true, false, false, regs[1] >> 16 &
> 0x0FFF, shortWays[regs[1] >> 28], update );
>             push( true, false, false, true, false, regs[0] >> 16 &
> 0x0FFF, shortWays[regs[0] >> 28], update );
>             push( true, true, true, false, false, regs[1] & 0xFFF,
> shortWays[regs[1] >> 12 & 0xF], update );
>             push( true, true, false, true, false, regs[0] & 0xFFF,
> shortWays[regs[0] >> 12 & 0xF], update );
>             if( has1GPages() && maxExtCpuid >= 0x80000019u )
>                 cpuid( regs, 0x80000019u, 0 ),
>                 push( false, false, false, false, true, regs[0] >> 16 &
> 0xFFF, shortWays[regs[0] >> 28], update ),
>                 push( false, true, false, false, true, regs[0] & 0xFFF,
> shortWays[regs[1] >> 12 & 0xF], update ),
>                 push( true, false, false, false, true, regs[1] >> 16 &
> 0xFFF, shortWays[regs[0] >> 28], update ),
>                 push( true, true, false, false, true, regs[1] & 0xFFF,
> shortWays[regs[1] >> 12 & 0xF], update );
>             return nTLBs;
>         };
>         tlbs.reserve( gatherTLBs( false ) );
>         gatherTLBs( true );
>
> This function collects the TLB-sizes for AMD-CPUs. In one mode it just
> counts the number of entries (update = false), in th other it fills the
> vector tlbs. That prevents any reallocation of tlbs.
> And the push lambda prevents a huge amount of redundant code.

Which bit is the lambda? If I create a more compact version so that I
can see the whole thing more easily:

auto gatherTLBs = [&](bool update ) -> size_t
{
size_t nTLBs = 0;
auto push = [&](bool l2, code, _4k, _2M4M, _1G, unsigned n, ways,
bool update )
{
if( !n || !ways )
return;
++nTLBs;
if( update )
tlbs.emplace_back( (uint8_t)l2 + 1, !code ? DATA : CODE,
_4k, _2M4M, _2M4M, _1G, n, ways );
};

static auto longWays = []( uint8_t ways ) -> unsigned { return ways
!= 0xFF ? ways : -1; };
static unsigned shortWays[0x10] = { 0, 1, 2, 0, 4, 0, 8, 0, 16,
0, 32, 48, 64, 96, 128, (unsigned)-1 };
cpuid( regs, 0x80000005u, 0 );
push( F, F, T, F, F, regs[1] >> 16 & 0x0FF, longWays( regs[1] >>
24 ), update );
push( F, F, F, T, F, regs[0] >> 16 & 0x0FF, longWays( regs[0] >>
24 ), update );
push( F, T, T, F, F, regs[1] & 0xFF, longWays( regs[1] >> 8 &
0xFF ), update );
push( F, T, F, T, F, regs[0] & 0xFF, longWays( regs[0] >> 8 &
0xFF ), update );
cpuid( regs, 0x80000006u, 0 );
push( T, F, T, F, F, regs[1] >> 16 & 0x0FFF, shortWays[regs[1] >>
28], update );
push( T, F, F, T, F, regs[0] >> 16 & 0x0FFF, shortWays[regs[0] >>
28], update );
push( T, T, T, F, F, regs[1] & 0xFFF, shortWays[regs[1] >> 12 &
0xF], update );
push( T, T, F, T, F, regs[0] & 0xFFF, shortWays[regs[0] >> 12 &
0xF], update );
if( has1GPages() && maxExtCpuid >= 0x80000019u )
cpuid( regs, 0x80000019u, 0 ),
push( F, F, F, F, T, regs[0] >> 16 & 0xFFF, shortWays[regs[0]
>> 28], update ),
push( F, T, F, F, T, regs[0] & 0xFFF, shortWays[regs[1] >> 12
& 0xF], update ),
push( T, F, F, F, T, regs[1] >> 16 & 0xFFF, shortWays[regs[0]
>> 28], update ),
push( T, T, F, F, T, regs[1] & 0xFFF, shortWays[regs[1] >> 12
& 0xF], update );
return nTLBs;
};
tlbs.reserve( gatherTLBs( F ) );
gatherTLBs( T );

then push() just looks like an ordinary local function.

What could be significantly improved are all those bitfield ops. Ideally
you would use named bitfields within what is presumably a 32-bit
unsigned value, instead of all those mysterious shifts and masks.

Those 0xFFF masks mixed with 16-bit shifts look suspicious until you
realise these are 12+4-bit fields in each half of a 32-bit value.

Here even a simple GETBITS macro would improve both readability and
confidence that the code is correct.

I don't do named bitfields outside of a struct [in my languages], but at
least I can manage this:

macro F1 = 0..11
macro F2 = 12..15
macro F3 = 16..27
macro F4 = 28..31

push(F,F,F,F,T, regs[0].[F3], shortways[regs[1].F4)

Better if I knew what those fields were for then I could give proper names.

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.

I'd also have aliases for regs[0] and regs[1], such as R0 and R1 (after
all you write assembly using R0 not REGS[0]).

Those first 5 Bool parameters for push also look like they are ripe for
conversion to a single flag parameter containing 5 single-bit fields
(Just Or-ing named bit-masks would be better.)

Remember your original looked like this:

push( false, false, true, false, false, ...

What do each of these signify? At least, if using multiple parameters,
use keyword parameters combined with a default value, such as false,
then this example can become:

push(..., FlagA:true)

(Keyword parameters go after positional ones.) Again I don't know what
these mean so can't give a more useful name.

(Does C++ have keyword parameters? It looks like it doesn't.)

Re: Book or tutorial on standard C threads

<spfjmm$gun$1@dont-email.me>

  copy mid

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

  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 15:49:57 +0100
Organization: A noiseless patient Spider
Lines: 42
Message-ID: <spfjmm$gun$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 16 Dec 2021 14:49:58 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="9e4386c8391e0a62735831cf701b50dd";
logging-data="17367"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/OTrlqd9/dpR1KMDd948RO4C+AyKgSl08="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:HQEdrBovmhfPHLTsiLDYbFw4flQ=
In-Reply-To: <spfhn3$370$1@dont-email.me>
Content-Language: de-DE
 by: Bonita Montero - Thu, 16 Dec 2021 14:49 UTC

Am 16.12.2021 um 15:16 schrieb Bart:

> Which bit is the lambda? If I create a more compact version so that I
> can see the whole thing more easily:

There is no way to have it more readable than with the lambdas.

> then push() just looks like an ordinary local function.

push() saves a lot of redundant code and it does make sense only locally
within that function - a perfect case for a lambda.

> What could be significantly improved are all those bitfield ops.
> Ideally you would use named bitfields within what is presumably
> a 32-bit unsigned value, instead of all those mysterious shifts
> and masks.

I get the values from CPUID and it would make no sense to move that
to a bitfield'ed structure that because this should compile with
three compilers (MSVC, clang, g++) and they behave not absolutely
the same with bitfields.

> Those 0xFFF masks mixed with 16-bit shifts look suspicious until you
> realise these are 12+4-bit fields in each half of a 32-bit value.

What I do is correct, look at the corresponding CPUID-documentation.

> Here even a simple GETBITS macro would improve both readability and
> confidence that the code is correct.
>

Macros are a no-go since they're global and often not debuggable
(depending on the IDE).

> 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.

Of course the lambdas make the code more readable because they save
a huge amount of redundant code.

Re: Book or tutorial on standard C threads

<spfnln$e7j$1@dont-email.me>

  copy mid

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

  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 15:57:45 +0000
Organization: A noiseless patient Spider
Lines: 95
Message-ID: <spfnln$e7j$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 15:57:43 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3043536772e7831927a8259101779feb";
logging-data="14579"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+/S0/3WqbXy3bB2Q5JEabPfdWz2Ea/b/U="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:iev7nPsFPgjnRCGaNSjmmRJ99mM=
In-Reply-To: <spfjmm$gun$1@dont-email.me>
 by: Bart - Thu, 16 Dec 2021 15:57 UTC

On 16/12/2021 14:49, Bonita Montero wrote:
> Am 16.12.2021 um 15:16 schrieb Bart:
>
>> Which bit is the lambda? If I create a more compact version so that I
>> can see the whole thing more easily:
>
> There is no way to have it more readable than with the lambdas.
>
>> then push() just looks like an ordinary local function.
>
> push() saves a lot of redundant code and it does make sense only locally
> within that function - a perfect case for a lambda.

So which bit /is/ the lambda?!

>
>> What could be significantly improved are all those bitfield ops.
>> Ideally you would use named bitfields within what is presumably
>> a 32-bit  unsigned value, instead of all those mysterious shifts
>> and masks.
>
> I get the values from CPUID and it would make no sense to move that
> to a bitfield'ed structure that because this should compile with
> three compilers (MSVC, clang, g++) and they behave not absolutely
> the same with bitfields.

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.

>> Those 0xFFF masks mixed with 16-bit shifts look suspicious until you
>> realise these are 12+4-bit fields in each half of a 32-bit value.
>
> What I do is correct, look at the corresponding CPUID-documentation.
>
>> Here even a simple GETBITS macro would improve both readability and
>> confidence that the code is correct.

> Macros are a no-go since they're global and often not debuggable
> (depending on the IDE).

So, inlined functions, templates ... does C++ really have no better way
of isolating a specific bitfield in A than using:

(A>>x) & y

where x is the start bit, and y is so many 1-bits depending on the
field's width?

Here's a much better approach using only C features:

https://github.com/gcc-mirror/gcc/blob/master/gcc/config/i386/cpuid.h

>> 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.
>
> Of course the lambdas make the code more readable because they save
> a huge amount of redundant code.

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

Because I'm sorry but I just can't see it. All I can see is that it uses
CPUID to extract info into a bunch of registers. Then you extract some
fields from those into an array of values.

Given a way to call CPUID, you don't need any special language features
for what seems a rather trivial task.

It's also not clear whether this is real or made-up code, since the
information returned using 0x80000006 doesn't correspond with what
you're trying to extract. But then we don't know the mapping of regs[]
to rcx etc, nor whether cpuid() is a real thing, as I had trouble
finding some info on it.

BTW here's how I use cpuid [not C]:

static [16]char id

assem
mov eax, 0
cpuid
mov [id], ebx
mov [id+4], edx
mov [id+8], ecx
end

println "Processor ID =",id

This displays:

Processor ID = AuthenticAMD

Re: Book or tutorial on standard C threads

<spfp7o$pv7$1@dont-email.me>

  copy mid

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

  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 17:24:23 +0100
Organization: A noiseless patient Spider
Lines: 71
Message-ID: <spfp7o$pv7$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=utf-8
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 16:24:24 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="5c5380de63587e5edca61de9ce276e88";
logging-data="26599"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX187+qztZbwffyBADtsCTVvm7Iw2aS81pKc="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101
Thunderbird/78.11.0
Cancel-Lock: sha1:D0oy/sQ/4pO5YObo1vcgiM1v0uw=
In-Reply-To: <spfhn3$370$1@dont-email.me>
Content-Language: en-GB
 by: David Brown - Thu, 16 Dec 2021 16:24 UTC

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.

(Readability is in the eye of the beholder, and I'd rather not comment
here. I am also not commenting on the code itself, or how it could have
been written.)

>
> Those first 5 Bool parameters for push also look like they are ripe for
> conversion to a single flag parameter containing 5 single-bit fields
> (Just Or-ing named bit-masks would be better.)
>
> Remember your original looked like this:
>
>     push( false, false, true, false, false, ...
>
> What do each of these signify? At least, if using multiple parameters,
> use keyword parameters combined with a default value, such as false,
> then this example can become:
>
>     push(..., FlagA:true)
>
> (Keyword parameters go after positional ones.) Again I don't know what
> these mean so can't give a more useful name.
>
> (Does C++ have keyword parameters? It looks like it doesn't.)
>
>

No, C++ does not have keyword parameters. It is something that comes up
again and again in propositions, requests and suggestions, and hopefully
it will be included eventually. But there are large number of
possibilities and choices involved that make it surprisingly difficult
to pin down exactly how keyword parameters could be added to the language.

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.

Re: Book or tutorial on standard C threads

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

  copy mid

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

  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 17:03:23 +0000
Organization: A noiseless patient Spider
Lines: 20
Message-ID: <87mtl0wkh0.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> <spfjmm$gun$1@dont-email.me>
<spfnln$e7j$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain
Injection-Info: reader02.eternal-september.org; posting-host="b9f7989dd930ff4732a641e9d197fd11";
logging-data="8304"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/i4tNYzRdMNT+1ya+a5GCGZmHyLx+Fd04="
Cancel-Lock: sha1:LNPC3qKcxe/+pSEXMeNQvFdnl6c=
sha1:D4Gqc2VgM2raxkVqjsgNzYBVPWQ=
X-BSB-Auth: 1.c2b7eaf5ced21518fa16.20211216170323GMT.87mtl0wkh0.fsf@bsb.me.uk
 by: Ben Bacarisse - Thu, 16 Dec 2021 17:03 UTC

Bart <bc@freeuk.com> writes:

> On 16/12/2021 14:49, Bonita Montero wrote:
>> Am 16.12.2021 um 15:16 schrieb Bart:
>>
>>> Which bit is the lambda? If I create a more compact version so that I can see the whole thing more easily:
>> There is no way to have it more readable than with the lambdas.
>>
>>> then push() just looks like an ordinary local function.
>> push() saves a lot of redundant code and it does make sense only locally
>> within that function - a perfect case for a lambda.
>
> So which bit /is/ the lambda?!

The bit that starts [&], followed by a function header (with C++'s new
-> return_type syntax) and a block. I.e. most of the first line and all
but two lines of the rest of the posted code..

--
Ben.

Re: Book or tutorial on standard C threads

<spfurq$3ll$1@dont-email.me>

  copy mid

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

  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 18:00:27 +0000
Organization: A noiseless patient Spider
Lines: 49
Message-ID: <spfurq$3ll$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>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
Injection-Date: Thu, 16 Dec 2021 18:00:26 -0000 (UTC)
Injection-Info: reader02.eternal-september.org; posting-host="3043536772e7831927a8259101779feb";
logging-data="3765"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1+cwWeHywatzQOZU79vw0dpbEwroZYbo54="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101
Thunderbird/91.4.0
Cancel-Lock: sha1:0WM/bA3chMregesVIoke4W30+Ok=
In-Reply-To: <spfp7o$pv7$1@dont-email.me>
 by: Bart - Thu, 16 Dec 2021 18:00 UTC

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.

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

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

(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.)

Pages:123
server_pubkey.txt

rocksolid light 0.9.8
clearnet tor