Monday, March 6, 2017

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

Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Mar 06 12:03AM

On 05/03/2017 22:10, Rick C. Hodgin wrote:
> spent their entire lives teaching them false things which now they hold
> on to as though they are truths. Any efforts of outreach face that inertia,
> and are severely hampered by its effect on intelligent people.
 
The enemy (Christian preachers) have spent their entire lives preaching
false things which now they hold on to as though they are truths. Any
efforts of outreach face that inertia, and are severely hampered by its
effect on stupid, obtuse, fucktarded people who have invested so much
time and energy in falsehoods.
 
> https://image.slidesharecdn.com/judepart8-091029052835-phpapp02/95/jude-part-8-33-728.jpg?cb=1256794141
 
No Hell detected.
 
/Flibble
Real Troll <real.troll@trolls.com>: Mar 05 09:10PM -0400

On 05/03/2017 04:27, Rick C. Hodgin wrote:
> If
> you are sincere in your search, He will do this for you, because He
> loves you and He will honor your request.
 
So it is not automatic!! I knew there is a catch somewhere.
 
Did you go to the church today? Did you meet any nice and not very nice
people? Did you tell them to start programming in C, C++ and C# to make
them employable? Trump is going to stop all forms of migration so IT
talent would be in demand. Programmers would be in demand like Cobol
programmers were in demand when somebody managed to fool the world that
millennium bug is coming!!
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 05 05:58PM -0800

Many people professing to know Jesus Christ have done things that
are not Christ-like. This demonstrates to all that they were not doing
the Lord's work, but are misguided by the enemy.
 
It is good to identify the false and heinous things false "Christians"
do, because God does not call us to be like them, or to teach those
false things, but rather to teach and lead rightly. It's why I point you
to Jesus Christ Himself, asking you to say a prayer to Him first to
then guide you to the place HE has for you in this world.
 
We do not answer to priests or pastors, but to Him directly. But He
still appoints priests snd pastors to be overseers, calling them to also
and always conduct themselves properly as a servant of the Lord,
and they too are subject to our calling them out and rebuking them
on wrong actions or teachings.
 
The Lord calls us to Him. We are saved by Him alone, and we are to
serve Him alone.
 
Thank you,
Rick C. Hodgin
Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk>: Mar 05 08:46PM

On 05/03/2017 19:01, Rick C. Hodgin wrote:
> People believe evolution is a fact. It does not align with observational
> science or genetic research. The Biblical account of "kinds" being made,
> diversifying out to the forms we see today does align with both:
 
More false assertions.
 
Evolution is fact regardless of whether or not people believe it is
fact: the evidence is there proving that evolution happens. There is a
theory of evolution that attempts to explain the fact of evolution but
the theory is quite separate from the fact.
 
/Flibble
Juha Nieminen <nospam@thanks.invalid>: Mar 06 08:42AM

> Go to church.
 
The irony is that sabbath is on saturday, not sunday. It was changed
by the Roman church in order to separate themselves from the jews.
 
Even according to your own religion you are distorting the commands
of your own god. Hypocrite.
Daniel <danielaparker@gmail.com>: Mar 06 01:06AM -0800

On Monday, March 6, 2017 at 3:43:03 AM UTC-5, Juha Nieminen wrote:
> > Go to church.
 
> The irony is that sabbath is on saturday, not sunday. It was changed
> by the Roman church in order to separate themselves from the jews.
 
Right. And Easter was a pagan festival, not a Christian one, there is no
celebration of Easter in the New Testament. It was a practical matter for the
Roman church to appropriate the pagan Spring festival, the northern bunny
goddess, the sweet bun offerings to the idols, etc.
 
Daniel
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 06 03:51AM -0800

The New Testament church is not like the Jews and the Old Testament
church. It's not about religion or rote. We don't have rigid festivals to
celebrate or adhere to. It's not an outside-in list of rules and regulations
to be followed. It is an inside-out change, a new birth into the spirit:
 
http://biblehub.com/kjv/john/3.htm
3 Jesus answered and said unto him, Verily, verily, I say unto
thee, Except a man be born again, he cannot see the kingdom
of God.
5 Jesus answered, Verily, verily, I say unto thee, Except a man be
born of water and of the Spirit, he cannot enter into the kingdom
of God.
6 That which is born of the flesh is flesh; and that which is born
of the Spirit is spirit.
 
A Christian is changed when they come to faith in Jesus Christ. The very
moment they ask Him to take away their sin, a real transaction takes
place, and the person is set free from their sin. This then means they
no longer have sin, and are no longer under any punishment from sin,
nor any condemnation by it. They are fully restored to their full
form, alive again spiritually, able to discern the things of God (He is
spirit, and His words are spirit and they are truth, but the natural-
only man cannot receive them because they are spirit. He is blind to
them because he has no faculties to discern them).
 
Our new spirit nature, the "born again" nature, asserts itself in a true
Christian's life, such that the inside-out welling-up spirit teaching and
inner guidance now moves us in this world. We cannot know where all
and what influences we will have, but He does. We simply live for Him
daily, hourly, minute-by-minute from that point forward, serving Him not
by ritual or custom, but as a pattern of a changed life.
 
8 The wind bloweth where it listeth, and thou hearest the sound
thereof, but canst not tell whence it cometh, and whither it goeth:
so is every one that is born of the Spirit.
 
It is the natural way for a born again Christian to move because we
then possess, by Jesus taking our sin away, the spirit nature.
 
Christians are to live for God daily, in all things. Not by religious rules or
rote. Most Christians assemble on the first day of the week, as a
remembrance of Jesus' resurrection day:
 
http://biblehub.com/kjv/john/20.htm
1 The first day of the week cometh Mary Magdalene early, when
it was yet dark, unto the sepulchre, and seeth the stone taken away
from the sepulchre...
17 Jesus saith unto her, Touch me not; for I am not yet ascended to
my Father: but go to my brethren, and say unto them, I ascend unto
my Father, and your Father; and to my God, and your God.
 
We are later taught in Paul's writings that any day is acceptable, and
there are many Christians who assemble on Saturday, Sunday, Tuesday,
Wednesday, and every other day. It is written:
 
http://biblehub.com/kjv/romans/14.htm
5 One man esteemeth one day above another: another esteemeth
every day alike. Let every man be fully persuaded in his own mind.
 
It is tradition that most churches assemble on certain days, not of
necessity on those particular days. It just works out better for
people for planning, scheduling, etc.
 
6 He that regardeth the day, regardeth it unto the Lord; and he
that regardeth not the day, to the Lord he doth not regard it. He
that eateth, eateth to the Lord, for he giveth God thanks; and he
that eateth not, to the Lord he eateth not, and giveth God thanks.
7 For none of us liveth to himself, and no man dieth to himself.
 
Our lives are continuously given to the Lord, because He is our blessed
Redeemer, our Hope solidified, our dreams instantiated, and our full and
bright guiding light in this dark world. We give Him our all-in-all.
 
8 For whether we live, we live unto the Lord; and whether we die,
we die unto the Lord: whether we live therefore, or die, we are the Lord's.
9 For to this end Christ both died, and rose, and revived, that he might
be Lord both of the dead and living.
 
Jesus also gave us similar guidance for communion:
 
http://biblehub.com/kjv/1_corinthians/11-25.htm
25 After the same manner also he took the cup, when he had supped,
saying, This cup is the new testament in my blood: this do ye,
as oft as ye drink it, in remembrance of me.
 
-----
Christianity is a higher calling than religion. It begins with a new birth,
and translates into a new life. The old passes away, the new is come:
 
http://www.biblehub.com/kjv/2_corinthians/5-17.htm
17 Therefore if any man be in Christ, he is a new creature: old
things are passed away; behold, all things are become new.
 
Thank you,
Rick C. Hodgin
leigh.v.johnston@googlemail.com: Mar 06 04:26AM -0800

You can dress it up any way you like but that does not change the fact that Christianity is a religion and no better than any other religion.
 
/Leigh
Daniel <danielaparker@gmail.com>: Mar 06 04:31AM -0800

On Sunday, March 5, 2017 at 1:44:03 PM UTC-5, Mr Flibble wrote:
 
> There is absolutely no contemporary evidence of Jesus's existence, none.
 
There is evidence, see for example
 
http://www.biblicalarchaeology.org/daily/people-cultures-in-the-bible/jesus-historical-jesus/did-jesus-exist/
 
Just not a lot of evidence, leaving the door open for skeptics,
 
http://www.exminister.org/Freke-Jesus-mysteries.html
 
> The gospels were written in the latter part of the first century and
> not by people who were "eye witnesses" to Jesus
 
That's true of the gospels. Paul, on the other hand, was a contemporary of
Jesus, although it's understood that Paul never met Jesus. Historians believe
that of the 27 documents in the New Testament that are attributed to Paul,
seven are genuine and from Paul's own hand, see
 
http://www.biblicalarchaeology.org/daily/people-cultures-in-the-bible/people-in-the-bible/the-quest-for-the-historical-paul/
 
 
> As we know Evolution is a fact
 
Well, the pope has no problem with evolution, the Catholic church has had no
problem with evolution since at least 1950, the same can be said of the more
intellectually grounded protestant churches,
 
> we know that Jesus's parents as described
> in the Bible could never have existed
 
Curiously, Matthew and Luke build two entirely different genealogies of the
lineage from David through Jesus, with no names in common. But it had been
prophesied that the Messiah would be descended from David, and historicizing
prophecy, that is, writing as history things that had been prophesied in
earlier texts, was a common technique of biblical writers.
 
> and it follows that neither did Jesus.
 
Umm ... no.
 
Daniel
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 06 04:38AM -0800

Christianity is not a religion in the traditional sense. It is a relationship,
a close personal relationship with Jesus Christ. His Holy Spirit dwells
within us, and He supernaturally guides us to "appointments" with
others where we will pray for people, teach, guide, advise, listen, learn,
act and do, help and team up to help, etc.
 
It's more than our lives moving by our will and impetus. He reaches in
and moves us as the John 3:8 reference teaches:
 
http://biblehub.com/kjv/john/3-8.htm
8 The wind bloweth where it listeth, and thou hearest the sound
thereof, but canst not tell whence it cometh, and whither it goeth:
so is every one that is born of the Spirit.
 
He is that wind guiding us through our lives as born again servants of God.
 
There is one mention of religion in the New Testament:
 
http://biblehub.com/kjv/james/1-27.htm
27 Pure religion and undefiled before God and the Father is this,
To visit the fatherless and widows in their affliction, and to
keep himself unspotted from the world.
 
For our "religion," we are to help and guide the needy and unfortunate,
and to keep ourselves holy.
 
Thank you,
Rick C. Hodgin
Daniel <danielaparker@gmail.com>: Mar 06 04:45AM -0800

On Sunday, March 5, 2017 at 1:07:23 PM UTC-5, gwowen wrote:
> Mr Flibble <flibbleREMOVETHISBIT@i42.co.uk> writes:
 
> > Jesus never existed; we know this because evolution is a fact.
 
> Worst. Syllogism. Ever.
 
Just so :-)
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 06 05:15AM -0800

To believe in evolution is to place death before sin. The Bible is
very clear that death entered in because of sin, and not before. It
is nothing less than a total denial of God, to the death of Jesus
Christ on the cross, His burial and resurrection, to believe in
evolution.
 
In addition, the nuances and complexities of information contained
within DNA is proving that evolution could not possibly exist. The
information contained within DNA is of such a complex ordered
structure it demands creation, in the same way a page with printed
text could only be concluded to have been arranged in that way on
purpose, even though the paper and ink are chemicals and can combine
through chemical processes, it's the specific arrangement and the
conveyance of information which makes them purposefully crafted.
 
The same is true with DNA, and that's something we're only truly
beginning to discover in this century, and even more so in this
decade.
 
Thank you,
Rick C. Hodgin
Daniel <danielaparker@gmail.com>: Mar 06 06:09AM -0800

On Sunday, March 5, 2017 at 8:58:49 PM UTC-5, Rick C. Hodgin wrote:
> Many people ... are misguided by the enemy.
 
I think by "enemy" you mean Knowledge :-) That's probably why, as suggested by your earlier posts, you don't read books by historical scholars about the history of religion, the books would only frighten you. But I think you should and I would encourage you to do so. Critical biblical scholarship was begun by Christian scholars as an application of the scientific approach into the humanities. Surprisingly (to me anyway) there are even fundamentalist Christian historians doing respected work in religious history. I can recommend "From Gods to God" by Avigdor Shinan and Yair Zakovitch, Old Testament Parallels by Victor H Matthews and Don C. Benjamin, "The Origins of Biblical Monotheism" and "The Early History of God" by Mark S Smith and "Stories from Ancient Canaan" by Michael D Cogan and Mark S Smith.
 
Be well,
Daniel
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 06 06:26AM -0800

On Monday, March 6, 2017 at 9:10:07 AM UTC-5, Daniel wrote:
> On Sunday, March 5, 2017 at 8:58:49 PM UTC-5, Rick C. Hodgin wrote:
> > Many people ... are misguided by the enemy.
 
> I think by "enemy" you mean Knowledge
 
What does the Bible teach about knowledge?
 
http://biblehub.com/kjv/1_corinthians/8.htm
 
1 Now as touching things offered unto idols, we know that we
all have knowledge. Knowledge puffeth up, but charity edifieth.
2 And if any man think that he knoweth any thing, he knoweth
nothing yet as he ought to know.
3 But if any man love God, the same is known of him.
 
Another translation to make more clear the use of older English:
 
1 Now about food sacrificed to idols: We know that "We all possess
knowledge." But knowledge puffs up while love builds up.
2 Those who think they know something do not yet know as they
ought to know.
3 But whoever loves God is known by God
 
And to be clear, the Bible teaches us who our enemy is:
 
http://biblehub.com/kjv/1_peter/5-8.htm
 
8 Be sober, be vigilant; because your adversary the devil, as a
roaring lion, walketh about, seeking whom he may devour:
 
The devil is our enemy. He is constantly examining us, poking us,
prodding us, investigating us, determining what it is we will believe
in which leads us away from God, and then reinforces that belief,
giving us more of the same so we will be led away by our own desires.
 
But for all who seek the truth, and do not follow after lusts for
lust's sake, but who will pursue the truth for the truth's sake, the
same are known to God. God then reaches in to their inmost core man
and flips invisible switches enabling them to come to Jesus Christ,
to know He is truth, to believe in Him, and to then be saved.
 
The rest who remain focused upon their lusts, turning away from God,
and turning toward their personal flavor of sin, the same remain in
judgment and condemnation from their sin, and will never come to be
saved.
 
-----
Seek your knowledge from the Bible, for such knowledge does not puff
up, but it humbles one's own soul, bringing low the heights of the
individual, forcing true acknowledgement within us as to our failings
and shortcomings before a holy God. And such knowledge then leads us
to repentance, and to come to Jesus and ask forgiveness for our sin.
 
It's been well said:
 
Either:
 
(1) Sin will keep you away from the Bible, or
(2) the Bible will keep you away from sin.
 
If you care about your eternal soul ... this is important knowledge
for you to gain, and an important application of that knowledge which
needs to take place in your life.
 
Thank you,
Rick C. Hodgin
Daniel <danielaparker@gmail.com>: Mar 06 06:45AM -0800

On Monday, March 6, 2017 at 9:26:30 AM UTC-5, Rick C. Hodgin wrote:
 
> Seek your knowledge from the Bible, for such knowledge does not puff
> up, but it humbles one's own soul ... And such knowledge then leads us
> to repentance ...
 
I don't think that qualifies as knowledge in the scientific meaning of the
term :-) No application of the scientific approach there.
 
Be well,
Daniel
"Rick C. Hodgin" <rick.c.hodgin@gmail.com>: Mar 06 06:52AM -0800

On Monday, March 6, 2017 at 9:46:26 AM UTC-5, Daniel wrote:
> > to repentance ...
 
> I don't think that qualifies as knowledge in the scientific meaning of the
> term :-) No application of the scientific approach there.
 
You are quite correct, but it is the way to eternal life. So, using
your reasoning powers, Daniel, what does that tell you about the power
of man's approach to knowledge using the scientific method, when that
approach has no ability to save one's soul, or to even lead people to
the right path which leads them to the One who can save them from
eternal damnation?
 
This message of salvation is for everybody to hear, but it is not for
everybody to receive. The ONLY people who will receive this message
of salvation are those who are being saved. The rest will perish.
 
It is sad, but it is the way of things (because people will not receive
Jesus, they themselves maintain the barriers which keep them from
salvation as He has already done everything necessary to save us, now
requiring only that we come to Him, repent, and ask forgiveness of our
sin and no matter what we've done, how bad it was, He will forgive us
and receive us into His eternal Kingdom. He could not have made it
any easier and still given us a free will choice.)
 
Thank you,
Rick C. Hodgin
Joseph Hesse <joeh@gmail.com>: Mar 06 10:20AM -0600

On 03/04/2017 10:27 PM, Rick C. Hodgin wrote:
> loves you and He will honor your request.
 
> Thank you,
> Rick C. Hodgin
 
This is a C++ newsgroup. I find it disgusting that there are replies to
this totally inappropriate post.
Joe
thebtc@hotmail.com: Mar 06 07:37AM -0800

Hi all,
I am having some troubles with the following code:
 
 
#include <stdlib.h>
#include <stdio.h>
#include <gsl/gsl_vector.h>
#include <gsl/gsl_multiroots.h>
 
using namespace std;
 
// create a data structure which will contain the parameters for the main function,
// f(x, y, z) = k1*x^2*y - k2*z^2, and the secondary reactions needed to calculate
// x, y and z of the main function, f(x, y) = 2*x - y - 2*x0 + y0 and
// f(y, z) = x + z - x0 -z0
struct rootFind_Params{
// k1, k2 rate constants
// x0, y0, z0 initial conditions
double k1, k2, x0, y0, z0;
};
 
// create a function that will store the vector result f(v, p), in f for argument
// v and parameters p
int rootFind(const gsl_vector* v, void* p, gsl_vector* f){
struct rootFind_Params* params = (struct rootFind_Params*)p;
const double k1 = (params->k1);
const double k2 = (params->k2);
const double x0 = (params->x0);
const double y0 = (params->y0);
const double z0 = (params->z0);
// return the i-th element of the vector v
const double x = gsl_vector_get(v,0);
const double y = gsl_vector_get(v,1);
const double z = gsl_vector_get(v,2);
// set the value of the i-th element of a vector f to f(x, y, z), f(x, y) or
// f(x, z)
gsl_vector_set(f, 0, (k1*x*x*y - k2*z*z));
gsl_vector_set(f, 1, (2*x - y - 2*x0 + y0));
gsl_vector_set(f, 2, (x + z - x0 -z0));
// return GSL_SUCCESS if calculation was completed successfully
return GSL_SUCCESS;
};
 
// do main computation
int main(){
// initialize solver:
// create a hybrid solver of type T
const gsl_multiroot_fsolver_type* T = gsl_multiroot_fsolver_hybrids;
// return a pointer to a newly allocated instance of a solver of type T
// for a system of three dimensions
gsl_multiroot_fsolver* s = gsl_multiroot_fsolver_alloc(T, 3);
// provide the function to solve:
// create a variable status which will report an error if the root-finding function
// is unsuccessful
int status;
// specify initial values of indices
size_t i, iter = 0;
// specify dimension of the system, ie. the number of components of the vectors
// v and f
const size_t n = 3;
// assign numerical values to the parameters in the data structure
struct rootFind_Params params = {1, 0.7, 0.5, 1, 0};
// create a function object f which can be passed to a solver
gsl_multiroot_function f = {&rootFind, n, &params};
// create an initial guess for x, y and z
double v_init[3] = {-2.0, -2.0, -2.0};
gsl_vector* v = gsl_vector_alloc(n);
gsl_vector_set(v, 0, v_init[0]);
gsl_vector_set(v, 1, v_init[1]);
gsl_vector_set(v, 2, v_init[2]);
// set the already allocated solver
gsl_multiroot_fsolver_set(s, &f, v);
 
print_state(iter, s);
 
do
{
// increment the index
iter++;
// iterate the solver
status = gsl_multiroot_fsolver_iterate(s);
print_state(iter, s);
// check if solver is stuck
if (status)
break;
// tests the residual value of f against the absolute error bound, 1e-7;
// returns GSL_SUCCESS if the condition sum_i |f_i| < 1e-7, else returns
// GSL_CONTINUE
status = gsl_multiroot_test_residual(s->f, 1e-7);
}
while (status == GSL_CONTINUE && iter < 1000);
 
// report error to user
printf("status = %s\n", gsl_strerror(status));
 
// free solver
gsl_multiroot_fsolver_free(s);
// free vector
gsl_vector_free(v);
 
return 0;
}
 
// display intermediate state of the solution
int print_state(size_t iter, gsl_multiroot_fsolver* s){
printf ("iter = %3u v = % .3f % .3f " "f(v) = % .3e % .3e\n", iter,
gsl_vector_get(s->v, 0),
gsl_vector_get(s->v, 1),
gsl_vector_get(s->v, 2),
gsl_vector_get(s->f, 0),
gsl_vector_get(s->f, 1),
gsl_vector_get(s->f, 2));
}
 
 
 
 
 
 
 
I am getting two errors:
rootFinding.cc:70:24: error: 'print_state' was not declared in this scope
print_state(iter, s);
and also this one,
rootFinding.cc:103:27: error: 'struct gsl_multiroot_fsolver' has no member named 'v'
gsl_vector_get(s->v, 0),
 
Why am I having these problems? Any help would be much appreciated!
Juha Nieminen <nospam@thanks.invalid>: Mar 06 08:38AM

> But `main` is not so much used that a few characters is a problem: in a
> million function program there's only 1 `main`.
 
In a million function program, how many of them need the trailing return
type syntax because the normal syntax doesn't suffice?
legalize+jeeves@mail.xmission.com (Richard): Mar 06 05:21AM

[Please do not mail me a copy of your followup]
 
Jorgen Grahn <grahn+nntp@snipabacken.se> spake the secret code
>you to create GUIs (that's what I think you mean). I create
>command-line interfaces and file formats fairly frequently, but last
>time I did GUIs was in 1994.
 
There is still lots of GUI work going on in C++ land. wxWidgets and
Qt are not losing any steam. However, for most simple types of GUI
(fill out this form and click OK), C# Windows Forms productivity can't
be beat. That was also true back in VC6 days as well -- VB6 supported
rapid application development in a way that just killed VC6. GUIs in
Java? Incredibly painful. GUIs in Python? Most people just bind to
Qt. Web front end gui in jQuery/Angular/bootstrap/etc? Really easy
but I still haven't seen a real graphical designer for those GUIs
like Windows Forms Designer for C# in Visual Studio.
 
For high performance computing and 3D graphics markets, I am willing
to bet there's still lots of C++ GUIs because the entire core of your
processing is highly likely to be done in C++ for performance reasons.
I work on a Qt C++ GUI every day, and less frequently a wxWidgets GUI,
but those application have been around for at least 10 years and both
are in the 3D graphics market segment. Toolkits like wxWidgets and Qt
give you high-level portable components that are rich enough to
satisfy most people's needs out of the box. If your needs aren't
satsified directly, it isn't hard to extend those frameworks with
custom widgets.
 
MFC? I'm only aware of legacy applications using it, not getting any
design wins in new applications. Tcl/Tk? Seems to have some following
in the perl/python community, but never really gained enough steam
to dominate. Every year someone posts in here how they have a new
GUI framework to kill all the others, but it will be very difficult to
displace the existing market momentum of even something dated like MFC
never mind things that are portable and still actively developed like
Qt and wxWidgets. My impression of MFC is that it occasionally gets
new features, but it is really only supported for legacy reasons at
this point. If MS is endorsing any GUI framework for C++ applications
these days, they seem to want you to use WinRT and WPF.
--
"The Direct3D Graphics Pipeline" free book <http://tinyurl.com/d3d-pipeline>
The Terminals Wiki <http://terminals-wiki.org>
The Computer Graphics Museum <http://computergraphicsmuseum.org>
Legalize Adulthood! (my blog) <http://legalizeadulthood.wordpress.com>
chris.m.thomasson.1@gmail.com: Mar 05 03:51PM -0800

This is through my Google account, because my eternal September server is acting odd right now. There might be some other duplicate posts coming in. Anyway;
 
Here is some experimental code that implements a multi-producer/consumer spinlock queue. Keep in mind that this can be converted into an entity that supports conditional waits through eventcounts.
 
Here is the c++11 code, does it work for you? If not, please explain every problem you encountered. Give it some time to complete, it should show progress in the console:
 
raw code, no ads:
 
http://pastebin.com/raw/hXQfrCSN
 
__________________________________________
#include <cstdio>
#include <memory>
#include <atomic>
#include <thread>
#include <functional>
 
 
#define N 10000000
 
#define mb_relaxed std::memory_order_relaxed
#define mb_acquire std::memory_order_acquire
#define mb_release std::memory_order_release
 
#define mb_fence(mb) std::atomic_thread_fence(mb)
 
/*
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;
}
*/
 
 
template<typename T, unsigned long T_depth>
struct single_producer_consumer_queue
{
struct cell
{
std::atomic<unsigned long> m_ver;
T m_data;
};
 
std::atomic<unsigned long> m_head;
std::atomic<unsigned long> m_tail;
cell m_cells[T_depth];
 
 
single_producer_consumer_queue()
: m_head(0),
m_tail(0)
{
for (unsigned long i = 0; i < T_depth; ++i)
{
m_cells[i].m_ver.store(i, mb_relaxed);
}
}
 
 
void produce(T const& in)
{
unsigned long ver = produce_begin();
while (!produce_commit(ver, in))
{
std::printf("produce wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
}
 
 
void consume(T& out)
{
unsigned long ver = consume_begin();
while (!consume_commit(ver, out))
{
std::printf("consume wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
 
}
 
 
unsigned long produce_begin()
{
return m_head.fetch_add(1, mb_relaxed);
}
 
bool produce_commit(unsigned long ver, T const& in)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver) return false;
mb_fence(mb_acquire);
c.m_data = in;
mb_fence(mb_release);
c.m_ver.store(ver + 1, mb_relaxed);
return true;
}
 
unsigned long consume_begin()
{
return m_tail.fetch_add(1, mb_relaxed);
}
 
bool consume_commit(unsigned long ver, T& out)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver + 1) return false;
mb_fence(mb_acquire);
out = c.m_data;
mb_fence(mb_release);
c.m_ver.store(ver + T_depth, mb_relaxed);
return true;
}
};
 
 
typedef single_producer_consumer_queue<unsigned long, 8192 * 2> spscq_t;
 
void producer(spscq_t* const q)
{
std::printf("producer(%p)\n", (void*)q);
 
for (unsigned long i = 0; i < N; ++i)
{
q->produce(i);
//std::printf("producer(%p)::produced(%lu)\n", (void*)&q, i);
std::this_thread::yield();
std::this_thread::yield();
 
if (!(i % 100000))
{
std::printf("producer(%p)::producer(%lu)\n", (void*)&q, i);
}
}
}
 
void consumer(spscq_t* const q)
{
std::printf("consumer(%p)\n", (void*)q);
 
unsigned long consumed = 0;
 
for (unsigned long i = 0; i < N; ++i)
{
 
q->consume(consumed);
std::this_thread::yield();
std::this_thread::yield();
 
 
if (! (i % 100000))
{
std::printf("consumer(%p)::consumed(%lu):%lu\n", (void*)&q, consumed, i);
}
}
 
std::printf("\n\n final: consumer(%p)::consumed(%lu)\n", (void*)q, consumed);
}
 
 
int main(void)
{
{
std::unique_ptr<spscq_t> q(new spscq_t);
 
std::thread consumer_thread(consumer, q.get());
std::thread producer_thread(producer, q.get());
 
producer_thread.join();
consumer_thread.join();
}
 
std::printf("\nComplete, hit <ENTER> to exit...\n");
std::fflush(stdout);
std::getchar();
 
return 0;
}
__________________________________________
 
 
One should see something kind of similar to this at the end of output:
__________________________________________
producer(019CF664)::producer(9300000)
consumer(0188F5F4)::consumed(9300000):9300000
producer(019CF664)::producer(9400000)
consumer(0188F5F4)::consumed(9400000):9400000
producer(019CF664)::producer(9500000)
consumer(0188F5F4)::consumed(9500000):9500000
producer(019CF664)::producer(9600000)
consumer(0188F5F4)::consumed(9600000):9600000
producer(019CF664)::producer(9700000)
consumer(0188F5F4)::consumed(9700000):9700000
producer(019CF664)::producer(9800000)
consumer(0188F5F4)::consumed(9800000):9800000
producer(019CF664)::producer(9900000)
consumer(0188F5F4)::consumed(9900000):9900000
 
 
final: consumer(0149FD78)::consumed(9999999)
 
Complete, hit <ENTER> to exit...
__________________________________________
 
 
The final should always equal 9999999 for the settings in the posted program related to N-1.
 
This test is for two threads a producer, and consumer. I will add more testes in this thread, over time. And answer any questions.
 
Again, can anybody compile this pile?
 
;^o
"Chris M. Thomasson" <invalid@invalid.invalid>: Mar 05 02:48PM -0800

Here is some experimental code that implements a multi-producer/consumer
spinlock queue. Keep in mind that this can be converted into an entity
that supports conditional waits through eventcounts.
 
Here is the c++11 code, does it work for you? If not, please explain
every problem you encountered. Give it some time to complete, it should
show progress in the console:
__________________________________________
#include <cstdio>
#include <memory>
#include <atomic>
#include <thread>
#include <functional>
 
 
#define N 10000000
 
#define mb_relaxed std::memory_order_relaxed
#define mb_acquire std::memory_order_acquire
#define mb_release std::memory_order_release
 
#define mb_fence(mb) std::atomic_thread_fence(mb)
 
/*
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;
}
*/
 
 
template<typename T, unsigned long T_depth>
struct single_producer_consumer_queue
{
struct cell
{
std::atomic<unsigned long> m_ver;
T m_data;
};
 
std::atomic<unsigned long> m_head;
std::atomic<unsigned long> m_tail;
cell m_cells[T_depth];
 
 
single_producer_consumer_queue()
: m_head(0),
m_tail(0)
{
for (unsigned long i = 0; i < T_depth; ++i)
{
m_cells[i].m_ver.store(i, mb_relaxed);
}
}
 
 
void produce(T const& in)
{
unsigned long ver = produce_begin();
while (!produce_commit(ver, in))
{
std::printf("produce wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
}
 
 
void consume(T& out)
{
unsigned long ver = consume_begin();
while (!consume_commit(ver, out))
{
std::printf("consume wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
 
}
 
 
unsigned long produce_begin()
{
return m_head.fetch_add(1, mb_relaxed);
}
 
bool produce_commit(unsigned long ver, T const& in)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver) return false;
mb_fence(mb_acquire);
c.m_data = in;
mb_fence(mb_release);
c.m_ver.store(ver + 1, mb_relaxed);
return true;
}
 
unsigned long consume_begin()
{
return m_tail.fetch_add(1, mb_relaxed);
}
 
bool consume_commit(unsigned long ver, T& out)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver + 1) return false;
mb_fence(mb_acquire);
out = c.m_data;
mb_fence(mb_release);
c.m_ver.store(ver + T_depth, mb_relaxed);
return true;
}
};
 
 
typedef single_producer_consumer_queue<unsigned long, 8192 * 2> spscq_t;
 
void producer(spscq_t* const q)
{
std::printf("producer(%p)\n", (void*)q);
 
for (unsigned long i = 0; i < N; ++i)
{
q->produce(i);
//std::printf("producer(%p)::produced(%lu)\n", (void*)&q, i);
std::this_thread::yield();
std::this_thread::yield();
 
if (!(i % 100000))
{
std::printf("producer(%p)::producer(%lu)\n", (void*)&q, i);
}
}
}
 
void consumer(spscq_t* const q)
{
std::printf("consumer(%p)\n", (void*)q);
 
unsigned long consumed = 0;
 
for (unsigned long i = 0; i < N; ++i)
{
 
q->consume(consumed);
std::this_thread::yield();
std::this_thread::yield();
 
 
if (! (i % 100000))
{
std::printf("consumer(%p)::consumed(%lu):%lu\n", (void*)&q,
consumed, i);
}
}
 
std::printf("\n\n final: consumer(%p)::consumed(%lu)\n", (void*)q,
consumed);
}
 
 
int main(void)
{
{
std::unique_ptr<spscq_t> q(new spscq_t);
 
std::thread consumer_thread(consumer, q.get());
std::thread producer_thread(producer, q.get());
 
producer_thread.join();
consumer_thread.join();
}
 
std::printf("\nComplete, hit <ENTER> to exit...\n");
std::fflush(stdout);
std::getchar();
 
return 0;
}
__________________________________________
 
 
One should see something kind of similar to this at the end of output:
__________________________________________
producer(019CF664)::producer(9300000)
consumer(0188F5F4)::consumed(9300000):9300000
producer(019CF664)::producer(9400000)
consumer(0188F5F4)::consumed(9400000):9400000
producer(019CF664)::producer(9500000)
consumer(0188F5F4)::consumed(9500000):9500000
producer(019CF664)::producer(9600000)
consumer(0188F5F4)::consumed(9600000):9600000
producer(019CF664)::producer(9700000)
consumer(0188F5F4)::consumed(9700000):9700000
producer(019CF664)::producer(9800000)
consumer(0188F5F4)::consumed(9800000):9800000
producer(019CF664)::producer(9900000)
consumer(0188F5F4)::consumed(9900000):9900000
 
 
final: consumer(0149FD78)::consumed(9999999)
 
Complete, hit <ENTER> to exit...
__________________________________________
 
 
The final should always equal 9999999 for the settings in the posted
program related to N-1.
 
This test is for two threads a producer, and consumer. I will add more
testes in this thread, over time. And answer any questions.
 
Again, can anybody compile this pile?
 
;^o
"Chris M. Thomasson" <invalid@invalid.invalid>: Mar 05 02:29PM -0800

Here is some experimental code that implements a multi-producer/consumer
spinlock queue. Keep in mind that this can be converted into an entity
that supports conditional waits through eventcounts.
 
Here is the c++11 code, does it work for you? If not, please explain
every problem you encountered. Give it some time to complete, it should
show progress in the console:
__________________________________________
#include <cstdio>
#include <memory>
#include <atomic>
#include <thread>
#include <functional>
 
 
#define N 10000000
 
#define mb_relaxed std::memory_order_relaxed
#define mb_acquire std::memory_order_acquire
#define mb_release std::memory_order_release
 
#define mb_fence(mb) std::atomic_thread_fence(mb)
 
/*
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;
}
*/
 
 
template<typename T, unsigned long T_depth>
struct single_producer_consumer_queue
{
struct cell
{
std::atomic<unsigned long> m_ver;
T m_data;
};
 
std::atomic<unsigned long> m_head;
std::atomic<unsigned long> m_tail;
cell m_cells[T_depth];
 
 
single_producer_consumer_queue()
: m_head(0),
m_tail(0)
{
for (unsigned long i = 0; i < T_depth; ++i)
{
m_cells[i].m_ver.store(i, mb_relaxed);
}
}
 
 
void produce(T const& in)
{
unsigned long ver = produce_begin();
while (!produce_commit(ver, in))
{
std::printf("produce wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
}
 
 
void consume(T& out)
{
unsigned long ver = consume_begin();
while (!consume_commit(ver, out))
{
std::printf("consume wait ver %lu\n", ver);
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
std::this_thread::yield();
}
 
}
 
 
unsigned long produce_begin()
{
return m_head.fetch_add(1, mb_relaxed);
}
 
bool produce_commit(unsigned long ver, T const& in)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver) return false;
mb_fence(mb_acquire);
c.m_data = in;
mb_fence(mb_release);
c.m_ver.store(ver + 1, mb_relaxed);
return true;
}
 
unsigned long consume_begin()
{
return m_tail.fetch_add(1, mb_relaxed);
}
 
bool consume_commit(unsigned long ver, T& out)
{
cell& c = m_cells[ver & (T_depth - 1)];
if (c.m_ver.load(mb_relaxed) != ver + 1) return false;
mb_fence(mb_acquire);
out = c.m_data;
mb_fence(mb_release);
c.m_ver.store(ver + T_depth, mb_relaxed);
return true;
}
};
 
 
typedef single_producer_consumer_queue<unsigned long, 8192 * 2> spscq_t;
 
void producer(spscq_t* const q)
{
std::printf("producer(%p)\n", (void*)q);
 
for (unsigned long i = 0; i < N; ++i)
{
q->produce(i);
//std::printf("producer(%p)::produced(%lu)\n", (void*)&q, i);
std::this_thread::yield();
std::this_thread::yield();
 
if (!(i % 100000))
{
std::printf("producer(%p)::producer(%lu)\n", (void*)&q, i);
}
}
}
 
void consumer(spscq_t* const q)
{
std::printf("consumer(%p)\n", (void*)q);
 
unsigned long consumed = 0;
 
for (unsigned long i = 0; i < N; ++i)
{
 
q->consume(consumed);
std::this_thread::yield();
std::this_thread::yield();
 
 
if (! (i % 100000))
{
std::printf("consumer(%p)::consumed(%lu):%lu\n", (void*)&q,
consumed, i);
}
}
 
std::printf("\n\n final: consumer(%p)::consumed(%lu)\n", (void*)q,
consumed);
}
 
 
int main(void)
{
{
std::unique_ptr<spscq_t> q(new spscq_t);
 
std::thread consumer_thread(consumer, q.get());
std::thread producer_thread(producer, q.get());
 
producer_thread.join();
consumer_thread.join();
}
 
std::printf("\nComplete, hit <ENTER> to exit...\n");
std::fflush(stdout);
std::getchar();
 
return 0;
}
__________________________________________
 
 
One should see something kind of similar to this at the end of output:
__________________________________________
producer(019CF664)::producer(9300000)
consumer(0188F5F4)::consumed(9300000):9300000
producer(019CF664)::producer(9400000)
consumer(0188F5F4)::consumed(9400000):9400000
producer(019CF664)::producer(9500000)
consumer(0188F5F4)::consumed(9500000):9500000
producer(019CF664)::producer(9600000)
consumer(0188F5F4)::consumed(9600000):9600000
producer(019CF664)::producer(9700000)
consumer(0188F5F4)::consumed(9700000):9700000
producer(019CF664)::producer(9800000)
consumer(0188F5F4)::consumed(9800000):9800000
producer(019CF664)::producer(9900000)
consumer(0188F5F4)::consumed(9900000):9900000
 
 
final: consumer(0149FD78)::consumed(9999999)
 
Complete, hit <ENTER> to exit...
__________________________________________
 
 
The final should always equal 9999999 for the settings in the posted
program related to N-1.
 
This test is for two threads a producer, and consumer. I will add more
testes in this thread, over time. And answer any questions.
 
Again, can anybody compile this pile?
 
;^o
"Chris M. Thomasson" <invalid@invalid.invalid>: Mar 05 08:49PM -0800

On 3/5/2017 2:48 PM, Chris M. Thomasson wrote:
 
> Here is the c++11 code, does it work for you? If not, please explain
> every problem you encountered. Give it some time to complete, it should
> show progress in the console:
[...]
 
The code has a little bastard in there that makes the output seem as if
the two threads have two different queues! This is because the output
via printf is taking a pointer to the threads local space for holding
the damn pointer!
 
Take a look at line 170 here:
 
http://pastebin.com/hXQfrCSN
 
line 170: std::printf("consumer(%p)::consumed(%lu):%lu\n", (void*)&q,
consumed, i);
 
 
ummm,, wrt is that &q!!!!
 
damn!
"Chris M. Thomasson" <invalid@invalid.invalid>: Mar 05 07:22PM -0800

my server was acting funny. One can take a look at a post over on alt.test:
 
https://groups.google.com/d/topic/alt.test/1_j5evPEitw/discussion
 
;^o
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: