Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.c > #163915
| From | Bart <bc@freeuk.com> |
|---|---|
| Newsgroups | comp.lang.c |
| Subject | Re: Book or tutorial on standard C threads |
| Date | 2021-12-17 10:59 +0000 |
| Organization | A noiseless patient Spider |
| Message-ID | <sphqj1$e9d$1@dont-email.me> (permalink) |
| References | (4 earlier) <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> |
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.
Back to comp.lang.c | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Book or tutorial on standard C threads Mehdi Amini <atorrses@gmail.com> - 2021-12-11 10:06 +0330
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-11 08:29 +0100
Re: Book or tutorial on standard C threads gazelle@shell.xmission.com (Kenny McCormack) - 2021-12-13 08:12 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-14 17:41 +0100
Re: Book or tutorial on standard C threads Thiago Adams <thiago.adams@gmail.com> - 2021-12-13 09:16 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-14 17:47 +0100
Re: Book or tutorial on standard C threads scott@slp53.sl.home (Scott Lurndal) - 2021-12-14 17:13 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-14 18:43 +0100
Re: Book or tutorial on standard C threads Guillaume <message@bottle.org> - 2021-12-14 19:23 +0100
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-14 20:16 +0100
Re: Book or tutorial on standard C threads Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-12-15 04:02 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-15 17:53 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-15 17:26 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-15 18:30 +0100
Re: Book or tutorial on standard C threads scott@slp53.sl.home (Scott Lurndal) - 2021-12-15 17:49 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-15 19:19 +0100
Re: Book or tutorial on standard C threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-15 17:44 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-15 20:23 +0100
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-16 07:54 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-16 14:16 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-16 15:49 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-16 15:57 +0000
Re: Book or tutorial on standard C threads Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-12-16 17:03 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-16 20:08 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-16 20:48 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-17 07:19 +0100
Re: Book or tutorial on standard C threads David Brown <david.brown@hesbynett.no> - 2021-12-16 17:24 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-16 18:00 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-16 20:06 +0100
Re: Book or tutorial on standard C threads David Brown <david.brown@hesbynett.no> - 2021-12-16 20:14 +0100
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-17 09:30 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-17 19:06 +0100
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-18 03:07 -0800
Re: Book or tutorial on standard C threads David Brown <david.brown@hesbynett.no> - 2021-12-18 18:33 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-17 18:19 +0000
Re: Book or tutorial on standard C threads David Brown <david.brown@hesbynett.no> - 2021-12-18 18:45 +0100
Re: Book or tutorial on standard C threads Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-12-16 21:45 +0000
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-16 23:02 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-18 13:45 +0100
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-18 06:02 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-18 15:31 +0100
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-18 07:12 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-18 16:45 +0100
Re: Book or tutorial on standard C threads Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-12-18 23:38 +0000
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-19 10:40 -0800
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-19 19:07 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-19 20:17 +0100
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-19 12:41 -0800
Re: Book or tutorial on standard C threads Malcolm McLean <malcolm.arthur.mclean@gmail.com> - 2021-12-20 03:21 -0800
Re: Book or tutorial on standard C threads Öö Tiib <ootiib@hot.ee> - 2021-12-20 09:39 -0800
Re: Book or tutorial on standard C threads scott@slp53.sl.home (Scott Lurndal) - 2021-12-16 18:32 +0000
Re: Book or tutorial on standard C threads David Brown <david.brown@hesbynett.no> - 2021-12-16 20:27 +0100
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-16 20:33 +0100
Re: Book or tutorial on standard C threads Bart <bc@freeuk.com> - 2021-12-17 10:59 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-17 13:08 +0100
Re: Book or tutorial on standard C threads scott@slp53.sl.home (Scott Lurndal) - 2021-12-17 16:25 +0000
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-17 17:38 +0100
Re: Book or tutorial on standard C threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-16 16:03 -0800
Re: Book or tutorial on standard C threads Ben Bacarisse <ben.usenet@bsb.me.uk> - 2021-12-17 00:12 +0000
Re: Book or tutorial on standard C threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-16 17:05 -0800
Re: Book or tutorial on standard C threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-16 17:07 -0800
Re: Book or tutorial on standard C threads "Chris M. Thomasson" <chris.m.thomasson.1@gmail.com> - 2021-12-19 17:23 -0800
Re: Book or tutorial on standard C threads Bonita Montero <Bonita.Montero@gmail.com> - 2021-12-20 07:35 +0100
csiph-web