Friday, October 1, 2021

Digest for comp.lang.c++@googlegroups.com - 25 updates in 3 topics

Bonita Montero <Bonita.Montero@gmail.com>: Oct 01 03:32AM +0200

Am 30.09.2021 um 22:20 schrieb Chris M. Thomasson:
 
>> When you use wait-free or lock-free algorithms and there's no data
>> you have to poll.
 
> Why?
 
Because you don't have to wait in the kernel.
RadicalRabbit@theburrow.co.uk: Oct 01 09:17AM

On Thu, 30 Sep 2021 13:00:53 -0700
>these I did last year:
 
>https://youtu.be/DSiWvF5QOiI
 
>https://youtu.be/QFPSYsYUKBA
 
Very impressive. Could use maybe a few more colours though.
"Öö Tiib" <ootiib@hot.ee>: Oct 01 04:43AM -0700

On Friday, 1 October 2021 at 04:32:18 UTC+3, Bonita Montero wrote:
> >> you have to poll.
 
> > Why?
> Because you don't have to wait in the kernel.
 
What a thread does when its input queue is empty?
Bonita Montero <Bonita.Montero@gmail.com>: Oct 01 02:59PM +0200

Am 01.10.2021 um 13:43 schrieb Öö Tiib:
 
>>> Why?
>> Because you don't have to wait in the kernel.
 
> What a thread does when its input queue is empty?
 
If it hasn't anything other to do than "waiting" for a new entry it
spins. Lock-free and wait-free datastructures are idiocracy except
from lock-free stacks.
Branimir Maksimovic <branimir.maksimovic@icloud.com>: Oct 01 01:07PM

> these I did last year:
 
> https://youtu.be/DSiWvF5QOiI
 
> https://youtu.be/QFPSYsYUKBA
An error occurred. Please try again later. (Playback ID: pHR4vgIqqp13ECHz)
Learn More
 
--
 
7-77-777
Evil Sinner!
Branimir Maksimovic <branimir.maksimovic@icloud.com>: Oct 01 01:08PM

>>> you have to poll.
 
>> Why?
 
> Because you don't have to wait in the kernel.
 
If you don't spin it is not lock :P
problem is that only way you don't synchronize
is when things are *independent* from each other :P
 
--
 
7-77-777
Evil Sinner!
Branimir Maksimovic <branimir.maksimovic@icloud.com>: Oct 01 01:10PM


> If it hasn't anything other to do than "waiting" for a new entry it
> spins. Lock-free and wait-free datastructures are idiocracy except
> from lock-free stacks.
Poof. you spin me around like a record? :P
 
--
 
7-77-777
Evil Sinner!
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 01 01:04PM -0700

On 10/1/2021 5:59 AM, Bonita Montero wrote:
 
>> What a thread does when its input queue is empty?
 
> If it hasn't anything other to do than "waiting" for a new entry it
> spins.
 
Huh? Ever heard of a futex, or an eventcount? Take a lock-free dynamic
stack into account. When its empty we can use, say, a futex to wait on
it. This would be the slow-path. A fast-path is when the stack is not
empty. There is a big difference between a fast and a slow path. The
former is lock-free, the latter might have to wait.
 
This even works for wait-free structures. In this case, the fast-path
would be wait-free.
 
 
> Lock-free and wait-free datastructures are idiocracy except
> from lock-free stacks.
 
Sure. Whatever you say Bonita. Cough.... Cough... ;^)
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 01 01:08PM -0700

On 10/1/2021 6:07 AM, Branimir Maksimovic wrote:
 
>> https://youtu.be/QFPSYsYUKBA
> An error occurred. Please try again later. (Playback ID: pHR4vgIqqp13ECHz)
> Learn More
 
That's odd. The links I posted work for me. Just checked them. Humm...
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 01 01:11PM -0700


>> https://youtu.be/DSiWvF5QOiI
 
>> https://youtu.be/QFPSYsYUKBA
 
> Very impressive.
 
Thank you very much for the kind comment! :^)
 
 
> Could use maybe a few more colours though.
 
Yeah, they could. Humm... I am working on another animation using a more
robust coloring algorithm for the field lines. Here is an example:
 
https://fractalforums.org/gallery/1612-300921002353.png
 
The coloring for that one is more dynamic. Also, I am thinking about
cycling the colors during animation.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 01 01:19PM -0700


>> She is clever.
 
> Clever in a small area. She seems to have limited knowledge of development
> and OS methodologies that arn't commonly used in Windows however.
 
She seems to make absolute statements based on her rather narrow views.
Iirc, she even said something akin to a mutex implementation must use
compare-and-swap. I showed her how to do one using only exchange.
Recently, in this thread she said a lock-free structure, say a lock-free
stack, has to use spin-polling to wait for an empty state to become,
non-empty. Well, she is wrong, yet again.
"Chris M. Thomasson" <chris.m.thomasson.1@gmail.com>: Oct 01 01:20PM -0700

On 10/1/2021 5:59 AM, Bonita Montero wrote:
 
> If it hasn't anything other to do than "waiting" for a new entry it
> spins. Lock-free and wait-free datastructures are idiocracy except
> from lock-free stacks.
 
So a lock-free stack is okay with you, but not a lock-free queue? Why?
Bonita Montero <Bonita.Montero@gmail.com>: Oct 01 07:48PM +0200

On today's x86-CPUs there is a prefetching-instruction which loads
cacheline into an cache-level chosable by a parameter for this in-
struction. But I often wondered what is the most appropriate pre-
fetching-distance. So I wrote a program which you can give a maxi-
mum block-size and it incrementally scans this block lineary from
a beginning of a block-size of 4kB up to a default of 64MB, but
you can chose a larger maximum (nk, nm, ng parameter, the parame-
ter can be a float). The prefetching is done with an incrementing
distance, from zero (special case without prefetching) to 512
cachelines (assuming a L1- cacheline-size of 64 bytes, which fits
for all x86 CPUs for decades). It first CLFLUSHs the cachelines
it scans afterwards. It only scans a block if the prefetching
-distance is up to one fourth of the block-size. The tailing part
of the block which would give a prefetching beyond the block is
scanned without prefetching to simulate a common optimization.
It runs the test multiple times and takes the fastest timing.
On Windows it sets it thread-affinity to CPU 0 and the priority
as high as possible. On Linux it sets only the affinity. So it
would be best to run the benchmark with "nice -20 ./a.out".
 
So here's the source (C++17):
 
#if defined(_MSC_VER)
#define NOMINMAX
#include <Windows.h>
#elif defined(__unix__)
#include <unistd.h>
#include <sched.h>
#include <pthread.h>

No comments: