Wednesday, March 13, 2019

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

blt_4h9eyv9m_7@ai8rhnz2.com: Mar 05 05:16PM

On Tue, 5 Mar 2019 08:35:41 -0800 (PST)
>That doesn't help, because it still doesn't have a unique answer, just
>different answers on different implementations of C++. All you've done
>by changing it to "output" is to widen the range of possibilities.
 
So C++ compilers behave differently with the same source code? So perhaps you
think when presented with "i++" they'll actually do a subtract? Or if I'd
asked what is the difference between ++ and -- in the output you'd have
quibbled about the meaning of output then too?
 
>No, it's only questions about the output of an unspecified compiler that
 
[Drivel snipped].
 
I think we've established you didn't understand the question. Don't
embarrass yourself any further.
blt_wegy@mr3qwrpz7zr0ss9hctqd2nd.com: Mar 06 12:19PM

On Wed, 6 Mar 2019 11:08:48 +0100
 
>> So that compiler would return the result of "i=2;i++" as i = 1?
 
>No. Try again, but this time read carefully and /think/. What does it
>mean to subtract -1 ?
 
Ooo, I've no idea, thats such complex maths!
 
Never mind Rainman, clearly you don't get sarcasm either as well as not
understanding a simple original question.
 
Its fairly clear this group is a waste of time.
James Kuyper <jameskuyper@alumni.caltech.edu>: Mar 07 07:55AM -0500

> working in programming it would be pretty obvious to anyone who's not
> aspergers that it was sarcasm. Don't try and cover your inability to understand
> emotion or read between the lines by self important bluster.
 
The fundamental problem with that explanation is that your comment makes
no sense as sarcasm - whereas it's entirely plausible that, in your
haste to insult anyone and everyone who disagrees with you, you missed
the minus sign. You can claim otherwise. You might even be telling the
truth - but if it is true, you're out of luck, because this particular
truth is too implausible in this context to be believed.
blt_j9u_@4t0h9a2.gov: Mar 07 10:31AM

On Thu, 7 Mar 2019 10:50:53 +0100
>understand
>> emotion or read between the lines by self important bluster.
 
>Do you really expect anyone to believe you? Sure, you know what
 
Believe what you like. Your ridiculous attempt to get yourself out of a corner
you painted yourself into is quite amusing however :)
 
>Keep your xenophobia insults to yourself.
 
We'll note down xenophobia as another subject you don't have a clue about
shall we.
blt_t6tbvj09jy@qrzz1g0rb.ac.uk: Mar 05 04:08PM

On Tue, 5 Mar 2019 12:16:30 +0100
>you that this is not something defined by the language. The language
>does not even require a compiler to generate object code - he gave the
>example of generating asm.js output.
 
And that is relevant to my question how exactly? I said object code, I could
easily have just said output.
 
>The wide variety of C++ compilers, options, flags, target chips,
>non-native targets, etc., show how meaningless it is to ask "what do
>compilers generate here".
 
Oh ok. So any question regarding the output of a compiler is meaningless
is it because there could be multiple output types?
 
>So switch off the condescending and smart-ass attitude, ask your
 
I suggest you take your own advice.
 
>questions, then read the answers. Maybe you'll learn something -
>perhaps not an answer to the question you asked, but this is a
>discussion group and not a paid-for support line.
 
Discussion groups involve questions. Perhaps you don't quite understand how
usenet works.
blt_mj28k@ov9jxwu4h9kk.gov: Mar 07 08:54AM

On Wed, 6 Mar 2019 14:15:57 +0100
>> understanding a simple original question.
 
>You can't cover your misunderstanding by retroactively claiming it was
>sarcasm. You failed to understand what I wrote because you were far too
 
Given that anyone who couldn't understand - -1 would have little chance
working in programming it would be pretty obvious to anyone who's not
aspergers that it was sarcasm. Don't try and cover your inability to understand
emotion or read between the lines by self important bluster.
bitrex <user@example.net>: Mar 05 11:40PM -0500

On 03/05/2019 09:07 PM, Manfred wrote:
 
>> R'
 
There isn't any sane application for a const rvalue reference that I
know of. I'm ready to be corrected...:)
blt_Gdd@2s6u1wctmk9lsbz.gov.uk: Mar 07 08:52AM

On Wed, 06 Mar 2019 14:40:12 +0200
>> reply.
 
>Good for you, as nobody here still has any clue what you actually wanted
>to ask.
 
I've stated 3 the question 3 times. I'd suggest you improve your English
comprehension before you accuse others of not making sense.
 
>Was it if the compiler logically does s/&&/&/ before starting to compile
>C++ code?
 
Oh congratulations, you finally figure out part of it. It only took 4 days.
Well done, your mummy must be proud of you.
blt_r80v_Gl2@slz3z1ayz.net: Mar 06 12:15PM

On Wed, 06 Mar 2019 11:50:40 +0200
 
>Nope, you were only called ignorant and fool after you refused to accept
>that your original question did not make much sense, and started to
>attack responders instead of trying to clarify your question.
 
It made perfect sense for anyone with a working brain. However it seems this
group isn't about answering queries, but rather on posters getting one over on
each other. Don't worry, I've asked the exact same question on a different
forum now and instead of pretend ignorance and pedancy I actually got a sensible
reply.
Ian Collins <ian-news@hotmail.com>: Mar 05 03:33PM +1300

On 05/03/2019 15:30, Stefan Ram wrote:
 
> But a recent version of gcc compiles this and prints:
 
> A
> d.a = 1
 
As does recent clang.
 
--
Ian.
blt_3cgb97v7@iword.net: Mar 05 05:19PM

On Tue, 5 Mar 2019 08:46:44 -0800 (PST)
>that C++ implementations always produce object code, and never generate
>javascript, whereas a counter-example to that belief has already been
>cited.
 
I don't fucking care what the compiler generates as output, it could be a
shakespear sonnet or the the Marseillaise. I care about whether there would be
any *DIFFERENCE* in output given 2 different types of of input. Sorry if this
is a complex concept for you and the others to grasp. Perhaps go back to
programming Hello World in BASIC.
 
>> self regarding pedants and aspergers sufferers who fixate on irrelevant
>> terminology and ignore or miss the point
 
>We "miss the point" because the question as asked was pointless. You're
 
No, you missed the point because you're stupid.
David Brown <david.brown@hesbynett.no>: Mar 06 02:15PM +0100


> Ooo, I've no idea, thats such complex maths!
 
> Never mind Rainman, clearly you don't get sarcasm either as well as not
> understanding a simple original question.
 
You can't cover your misunderstanding by retroactively claiming it was
sarcasm. You failed to understand what I wrote because you were far too
busy trying to find new smart-ass comments to make. The correct
response would have been an admission of the error - not compounding
your rudeness.
 
> Its fairly clear this group is a waste of time.
 
No one is asking you to post here.
Paavo Helde <myfirstname@osa.pri.ee>: Mar 06 02:40PM +0200

> each other. Don't worry, I've asked the exact same question on a different
> forum now and instead of pretend ignorance and pedancy I actually got a sensible
> reply.
 
Good for you, as nobody here still has any clue what you actually wanted
to ask.
 
Was it if the compiler logically does s/&&/&/ before starting to compile
C++ code? Or was it if the compiler emits the same assembler opcode for
passing either an lvalue or an rvalue reference into the function?
 
Nobody knows, and answers to those questions are different.
Sam <sam@email-scan.com>: Mar 07 08:24AM -0500


> > Do you mean C++ books for Java programmers?
 
> I think C++ for Java programmers might be what I'm look for since I like to
> believe that I'm somewhat versed in imperative programming languages..
 
You will actually find it easier to learn C++ if you put everything you know
about Java out of your mind.
 
Despite C++'s deceptively similar syntax, in many ways C++ is fundamentally
different from Java. It is quite common for someone with a Java background
to look at some C++ code that looks almost Java and think it does the same
thing. It does not, and this only causes constant confusion, and common
programming errors that the Java developer will not understand.
 
> Ideally I'd just like to just change the syntax. Ie, I really don't want to
> have to rewrite the core algorithms.
 
It is almost a certainty that you will have to. C++ is not Java. Java is
managed code. C++ is not. Java will take care of creating, baby-sitting, and
destroying all of your objects, after the last reference to each object goes
out of scope, and the object becomes subject to garbage collection.
 
There's nothing of that sort in C++. In C++ you have complete responsibility
for figuring out when objects are no longer needed, and must be destroyed.
Guess wrong one way, and your running program eats all available RAM in a
few seconds. Guess wrong the other way, and you get random crashes in some
completely different part of the code which has nothing wrong with it,
leaving you to wonder WTF is happening.
 
C++ is not Java. To correctly use C++ for anything beyond "Hello world!" you
need to fully understand C++'s fundamental scoping rules, and actually
understand how objects get created, when they should be created, and when
they should be destroyed. As a Java coder, this is something that you have
never learned, and you simply don't know because Java always did this for
you, by itself. But now you must learn all of this in order to write C++
code that doesn't nuke itself from high orbit, all the time. And you must
learn this 100% correctly. No margin for error, whatsoever. Otherwise your
code will simply not work.
 
So, no, it is unlikely that you will be able to simply take Java code that
does anything more complicated than printing "Hello world!", and just
replace it with equivalent C++ syntax.
Jorgen Grahn <grahn+nntp@snipabacken.se>: Mar 07 09:47PM

On Thu, 2019-03-07, Öö Tiib wrote:
>> tablet.
 
> The main issue there is that the Android and Windows
> Phone tools and API-s are quite different
[etc]
 
I was going to flame certain other unhelpful replies, but there's
enough negativity in the group.
 
So I'll praise this one instead. Practical, insightful and helpful.
 
(Disclaimer: I don't know anything about these APIs myself.)
 
/Jorgen
 
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
Horizon68 <horizon@horizon.com>: Mar 06 01:47PM -0800

On 3/6/2019 1:30 PM, Chris M. Thomasson wrote:
 
>> About my scalable algorithms and ARM processor architecture..
> [...]
 
> Code it up in C++11?
 
I will port them to ARM using Delphi and FreePascal, and after that i
will port them to ARM using C++.
 
 
Thank you,
Amine Moulay Ramdane.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 06 01:30PM -0800

On 3/6/2019 1:23 PM, Horizon68 wrote:
> Hello..
 
> About my scalable algorithms and ARM processor architecture..
[...]
 
Code it up in C++11?
Horizon68 <horizon@horizon.com>: Mar 06 01:23PM -0800

Hello..
 
 
About my scalable algorithms and ARM processor architecture..
 
I have thought more, and i am specialized in parallel programming
and synchronization algorithms, and i have invented many scalable
algorithms and there implementations, you will find some of them in my
website here:
 
https://sites.google.com/site/scalable68/
 
 
My scalable algorithms and there implementations are actually compatible
with x86 architecture, but I have just taken a look at the following ARM
processor, and even though it's not a TSO memory model, and even though
it is a weak memory model, i think i am more capable to easily port my
scalable algorithms to such ARM processors, so i will easily port many
of my "scalable" algorithms to such the following ARM processors, here
is how: i think i have to 64-byte align some of my variables
in my scalable algorithms implementations so that to be atomic or/and to
avoid false sharing, also it is good that the ARM processors such as
Cortex-A76 below have 64-byte cache lines and this cache line size of
64-byte is compatible with x86, so it will easy for me the work of
porting to ARM, and i will easily put the right fences for ARM in my
scalable algorithms implementation so that to be compatible with such
the following ARM processors and this step is easy
for me because i am more capable, now my scalable algorithms
implementations are compatible with x86 architecture
and i will soon easily port them to ARM.
 
Here is the Cortex-A76 - Microarchitectures - ARM
notice that it has 64-byte cache lines as x86:
 
 
https://en.wikichip.org/wiki/arm_holdings/microarchitectures/cortex-a76
 
 
So stay tuned ! because i will soon easily port all my scalable
algorithms to such ARM processors.
 
 
 
 
Thank you,
Amine Moulay Ramdane.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 06 12:03PM -0800

On 3/6/2019 4:31 AM, Bonita Montero wrote:
>> ___________________________
 
>> Now, this really reminds me of my algorihtm. :^)
 
> My implementation is just experimental.
 
It is still nice. My work is experimental as well, but then I found out
that my algorihtm has been used in the Go Language for the past 7 years.
Go figure. ;^)
 
 
> If you would write a clean
> implementation you would throw an exception if either counter saturates.
> With this LOCK XADD wouldn't be possible.
 
Humm... Well, I guess you could create a simple rule, if more than
0xFFFF writers hit your algorihtm at the same time, it is undefined
behavior, end of story. Mine has that wrt _more_ than LONG_MAX readers
hitting it at the same time: Well, another one bites the dust.
 
Also, you can check to see if the return value of XADD, say count, is
(count & 0x0000FFFF) == 0xFFFF. That means the writers just intruded
into the reader logic, and an exception should be thrown. Humm...
Bonita Montero <Bonita.Montero@gmail.com>: Mar 06 01:31PM +0100

> }
> ___________________________
 
> Now, this really reminds me of my algorihtm. :^)
 
My implementation is just experimental. If you would write a clean
implementation you would throw an exception if either counter saturates.
With this LOCK XADD wouldn't be possible.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 06 12:53PM -0800

On 3/6/2019 12:03 PM, Chris M. Thomasson wrote:
 
> Also, you can check to see if the return value of XADD, say count, is
> (count & 0x0000FFFF) == 0xFFFF. That means the writers just intruded
> into the reader logic, and an exception should be thrown. Humm...
 
That would be after the fact of the mutation. Shi% has already occurred,
then you get an exception. Different than CAS loop. However, a simple
rule that no more than 0xFFFF writers can hit it at the same time should
be sufficient. Perhaps have two different modes. One that throws on
anything that is not Kosher, and another one that relies on the user to
not break the rules.
 
For some reason choosing CAS just to throw when the user breaks the
rules, seems like putting "corks on the forks" to prevent people from
hurting themselves.
Paavo Helde <myfirstname@osa.pri.ee>: Mar 08 12:08AM +0200

On 7.03.2019 22:37, fir wrote:
> Some x = {10, 20, 30};
 
> }
 
> will it be initialised each time or only once or will not compile (im not touching compiler now and cant check)
 
x is defined inside the for loop body so it is initialized and destroyed
on each iteration. This is a good thing (tm).
 
If you do not want this you can define x outside the loop, and only
assign to it inside the loop. This means two-stage initialization, which
is a bit problematic as it makes the things more complicated and
error-prone.
 
 
> (not so long time ago i was stating some thread on close things (named "small c probem" but i tend to forgot such things)
 
> and how it is in c++, where such obiect like here Some x would have destructor and construictor... afair c++ enforces that constructor and destrctor are called constantly (which in some way is sorta cretinic i belive), hovever in mentioned thread i see i wrote i made some test with
> int initialized c++ way int a(10) and it was there working right way (right way imo is doing it only once for block, not for each loop turn
 
Strictly pairing a constructor call with a destructor call is called
RAII, which is the strongest point of C++, ever. If you want this to
happen only once, you define x outside of the loop or as a static (if
appropriate).
ram@zedat.fu-berlin.de (Stefan Ram): Mar 05 06:47PM

>Also, i++ might actually be required to perform a subtraction. That will
>be the case if i has an unsigned integer type and starts out containing
>the maximum value representable in that type. The standard defines the
 
Only recently, in
 
Message-ID: <blast-20190202162842@ram.dialup.fu-berlin.de>
Newsgroups: comp.lang.c
Subject: A blast from the future
 
, I posted code where »++i« is "translated into" »subl $1,«.
 
main.c
 
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
 
int main( void )
{ int i = 429;
a:; ++i;
int c; srand( c );
c = 7; srand( c );
if( i < 432 )goto a; }
 
translation (reformatted by me [S.R.])
 
movl $3, %ebx
a:
movl $7, %ecx call srand
movl $7, %ecx call srand
subl $1, %ebx jne a
 
The whole idea that a small function is "translated into"
something often cannot be applied today, because a small
function will often be inlined and then the result will be
optimized and the result of that optimization might not have
a single region that can be identified with the call of the
function anymore.
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 06 01:41AM -0800

On 3/6/2019 1:36 AM, Chris M. Thomasson wrote:
 
[...]
>     {
>         unsigned long head = m_head.fetch_add(1,
> std::memory_order_acquire);
 
^^^^^^^^^^^^^^^^^^^^^^^^^^
 
Actually, the memory barrier above can be relaxed.
 
 
>     {
>         unsigned long tail = m_tail.fetch_add(1,
> std::memory_order_acquire);
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
 
Ditto. These have no need for anything more than relaxed order.
 
[...]
"Chris M. Thomasson" <invalid_chris_thomasson_invalid@invalid.com>: Mar 06 01:36AM -0800

This is a bounded MPMC queue spinlock that I developed based on the
following awesome algorihtm:
 
http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
 
read _all_ of the following for some further context:
 
https://groups.google.com/d/topic/lock-free/acjQ3-89abE/discussion
 
It only uses fetch_add, and atomic loads and stores to manage the queue.
No CAS! Pretty neat. ;^)
 
It can be outfitted with eventcounts to get rid of the spinning...
 
 
Fwiw, the following is a Relacy test unit: Will port this to pure C++ in
a day or two:
_____________________________
/*
 
Experimental Bakery Queue Spinlock by Chris M. Thomasson
 
Based on the following CAS based original awesome version by:
 
http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue
 
read all of the following for further context:
 
https://groups.google.com/d/topic/lock-free/acjQ3-89abE/discussion
 
My tweak does not use CAS...:
 
<pseudo code, membars aside for a moment>
______________________________________________
struct cell { uint32_t ver; double state; };
 
uint32_t head = 0;
uint32_t tail = 0;
cell cells[N]; // N must be a power of 2
 
void init() {
for (uint32_t i = 0; i < N; ++i) cells[i].ver = i;
}
 
void producer(double state) {
uint32_t ver = XADD(&head, 1);
cell& c = cells[ver & (N - 1)];
while (LOAD(&c.ver) != ver) backoff();
c.state = state;
STORE(&c.ver, ver + 1);
}
 
double consumer() {
uint32_t ver = XADD(&tail, 1);
cell& c = cells[ver & (N - 1)];
while (LOAD(&c.ver) != ver + 1) backoff();
double state = c.state;
STORE(&c.ver, ver + N);
return state;
}
_______________________________________________*/
 
 
//#define RL_DEBUGBREAK_ON_ASSERT
//#define RL_MSVC_OUTPUT
//#define RL_FORCE_SEQ_CST
//#define RL_GC
 
 
#include <relacy/relacy_std.hpp>
#include <iostream>
 
 
// Some global vars directing the show...
// PRODUCERS must equal CONSUMERS for this test
#define PRODUCERS 4
#define CONSUMERS 4
#define THREADS (PRODUCERS + CONSUMERS)
#define ITERS 3
 
#define DEPTH 3
 
 
struct ct_mpmcq_spin
{
struct cell
{
std::atomic<unsigned long> m_ticket;
VAR_T(long) m_udata;
};
 
 
std::atomic<unsigned long> m_head;
std::atomic<unsigned long> m_tail;
cell m_cells[DEPTH];
 
 
ct_mpmcq_spin() : m_head(0), m_tail(0)
{
for (unsigned long i = 0; i < DEPTH; ++i)
{
m_cells[i].m_ticket.store(i, std::memory_order_relaxed);
}
}
 
 
void push_wait(long udata)
{
unsigned long head = m_head.fetch_add(1,
std::memory_order_acquire);
std::size_t head_idx = head % DEPTH;
 
cell& head_cell = m_cells[head_idx];
 
// spin on our ticket...
while (head_cell.m_ticket.load(std::memory_order_acquire) != head)
{
// backoff...
rl::yield(1, $);
}
 
// write, copy, ect...
VAR(head_cell.m_udata) = udata;
 
// commit...
head_cell.m_ticket.store(head + 1, std::memory_order_release);
}
 
 
long pop_wait()
{
unsigned long tail = m_tail.fetch_add(1,
std::memory_order_acquire);
std::size_t tail_idx = tail % DEPTH;
 
cell& tail_cell = m_cells[tail_idx];
 
// spin on our ticket...
while (tail_cell.m_ticket.load(std::memory_order_acquire) !=
tail + 1)
{
// backoff...
rl::yield(1, $);
}
 
// write, copy, ect...
long udata = VAR(tail_cell.m_udata);
 
// commit...
tail_cell.m_ticket.store(tail + DEPTH, std::memory_order_release);
 
return udata;
}
};
 
 
 
// Relacy Stack Test...
struct ct_mpmcq_spin_test_tweak
: rl::test_suite<ct_mpmcq_spin_test_tweak, THREADS>
{
ct_mpmcq_spin g_mpmc_queue;
 
ct_mpmcq_spin_test_tweak() {}
 
void before()
{
 
}
 
void after()
{
 
}
 
// reader
void consumer(unsigned int tidx)
{
for (unsigned int i = 0; i < ITERS; ++i)
{
g_mpmc_queue.push_wait(tidx);
}
}
 
 
// writer
void producer(unsigned int tidx)
{
for (unsigned int i = 0; i < ITERS; ++i)
{
unsigned long udata = g_mpmc_queue.pop_wait();
 
RL_ASSERT(udata != tidx);
}
}
 
 
void thread(unsigned int tidx)
{
if (tidx < PRODUCERS)
{
producer(tidx);
}
 
else
{
consumer(tidx);
}
}
};
 
 
 
// Test away... Or fly? Humm...
int main()
{
{
rl::test_params p;
 
p.iteration_count = 10000000;
//p.execution_depth_limit = 33333;
//p.search_type = rl::sched_bound;
//p.search_type = rl::fair_full_search_scheduler_type;
//p.search_type = rl::fair_context_bound_scheduler_type;
 
rl::simulate<ct_mpmcq_spin_test_tweak>(p);
}
 
return 0;
}
_____________________________
You received this digest because you're subscribed to updates for this group. You can change your settings on the group membership page.
To unsubscribe from this group and stop receiving emails from it send an email to comp.lang.c+++unsubscribe@googlegroups.com.

No comments: