Re: C++ Threads, what's the status quo?
James Kanze wrote:
Le Chaud Lapin wrote:
The point is that C++ and threading are alive and well. People use
them together. Some people use the native API of their OS, which is
not always pleasant to use. Some people wrap these API's.
The point is that you don't know that it works, and that it
works only by chance (and may actually fail once you start using
a multi-core processor). The point is that you don't have any
guarantees with regards to what the language or the compiler
provides.
I never asked the compiler for any guarantees. What did you study in
university? I do not mean to attack you personally, but frankly, these
concepts are as old as multi-threading itself. I am appalled that so
many people seem not to understand multi-threading.
Maybe your happen with a definition of "working" as "it hasn't
crashed yet", but my customers generally aren't.
One of my multi-threaded application has 11 threads in it at minimum,
rising to 35 if necessary. This application will never crash "because
of threading."
But I do not think it is fair to say that we do not understand the
importance of multi-threading programming by C++ programmers. We do.
What we are saying is that the fundamentals of multi-threading, barring
some massive break through in the state-of-the -art, are
well-understood,
Which explains why so many programmers get it wrong. (The
people who implemented std::basic_string in g++ are not idiots;
they're some of the more gifted programmers I know. Never the
less, there is a threading error in the code.)
There is no "threading" error in the code. If I write
int x == 10;
int thread1 ();
int thread2 ();
....and let those two threads fiddle with x without the protection of
mutual-exclusion, there will be contention. Are you saying that the
people who designed std:basic_string designed it expecting there would
be no contention?
and it is our opinion that those who think that the language
itself is somehow deficient in this regard are mistaken.
You can think what you like, but you can't argue with hard
facts. It is impossible, today, to write a multi-threaded
program with defined behavior.
I do it every day. I know how to write multi-threaded applications.
There are probably 10,000's of programmers who do. One should not
assume that others are unable to do that which he cannot.
For the moment, I think the committee has only begun to scratch
the surface with regards to primitives. Before defining the
primitives, it is necessary to define a basic memory model; what
it means to read or wite to memory.
I am going to give the committee the benefit of the doubt and assume
that at least some of them understand the basics of synchronization and
OS design. But the more I read this thread (no pun intended), the more
I get the feeling is that real problem is simply that there
C++-is-lacking-thread support crowd is primarily composed of people who
have very little or no experience with multi-threading.
I wish someone who writes operating system books for a living were
reading this. I cannot stop laughing as I am reading this post. The
examples presented so far, two threads modifying a global
variable....leaves me...speechless.
In all fairness, I know that there are probably a few lurking
16-year-olds who, though bright, having gotten around to mutual
exclusion, and are so not sure who has more insight, so I offer this
link to get you started so you can plainly see that this is a very old
concept:
http://en.wikipedia.org/wiki/Mutual_exclusion
I did not study computer sciencel, but if you are reading this, and you
studied computer science, and you do not understand the basics of
mutual exclusion, or equivalently,
if you are in anyway, even _one iota_, surprised that a global static
variable used by std::string cannot be accessed read/write by multiple
threads without a mutex, I am sorry, there is simply no excuse - you
should be ashamed of yourself! ?????? What do you expect??!!
See the following link: http://bardavid.com/mead/
"The mutual exclusion problem was formally defined by Edsger Dijkstra
in 1965."
These concepts are more than 40 years old, and multi-threaded
applications are written all the time, not just in C/C++, but in *many*
languages.
I am so perplexed by this discussion, I am going to over to the threads
group to see what they have to say.
-Le Chaud Lapin-
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]